<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP, DeriveFunctor, ViewPatterns, BangPatterns #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Tc.Solver.Flatten</span><span class="hs-special">(</span><span>
</span><span id="line-6"></span><span>   </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier">FlattenMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-7"></span><span>   </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten"><span class="hs-identifier">flatten</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenKind"><span class="hs-identifier">flattenKind</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenArgsNom"><span class="hs-identifier">flattenArgsNom</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-8"></span><span>   </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#rewriteTyVar"><span class="hs-identifier">rewriteTyVar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenType"><span class="hs-identifier">flattenType</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span>   </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#unflattenWanteds"><span class="hs-identifier">unflattenWanteds</span></a></span><span>
</span><span id="line-11"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html"><span class="hs-identifier">GHC.Tc.Types</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html"><span class="hs-identifier">GHC.Core.TyCo.Ppr</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html#pprTyVar"><span class="hs-identifier">pprTyVar</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html"><span class="hs-identifier">GHC.Tc.Types.Constraint</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html"><span class="hs-identifier">GHC.Core.Predicate</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html"><span class="hs-identifier">GHC.Tc.Types.Evidence</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html"><span class="hs-identifier">GHC.Core.TyCon</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html"><span class="hs-identifier">GHC.Core.TyCo.Rep</span></a></span><span>   </span><span class="hs-comment">-- performs delicate algorithm on types</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html"><span class="hs-identifier">GHC.Core.Coercion</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html"><span class="hs-identifier">GHC.Tc.Solver.Monad</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">TcS</span></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#SwapFlag"><span class="hs-identifier">SwapFlag</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Monad.html"><span class="hs-identifier">GHC.Utils.Monad</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Utils.Monad.html#zipWith3M"><span class="hs-identifier">zipWith3M</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#"><span class="hs-identifier">Data.Foldable</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#foldrM"><span class="hs-identifier">foldrM</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Arrow.html#"><span class="hs-identifier">Control.Arrow</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Control.Arrow.html#first"><span class="hs-identifier">first</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span>
</span><span id="line-42"></span><span class="hs-comment">{-
Note [The flattening story]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* A CFunEqCan is either of form
     [G] &lt;F xis&gt; : F xis ~ fsk   -- fsk is a FlatSkolTv
     [W]       x : F xis ~ fmv   -- fmv is a FlatMetaTv
  where
     x is the witness variable
     xis are function-free
     fsk/fmv is a flatten skolem;
        it is always untouchable (level 0)

* CFunEqCans can have any flavour: [G], [W], [WD] or [D]

* KEY INSIGHTS:

   - A given flatten-skolem, fsk, is known a-priori to be equal to
     F xis (the LHS), with &lt;F xis&gt; evidence.  The fsk is still a
     unification variable, but it is &quot;owned&quot; by its CFunEqCan, and
     is filled in (unflattened) only by unflattenGivens.

   - A unification flatten-skolem, fmv, stands for the as-yet-unknown
     type to which (F xis) will eventually reduce.  It is filled in


   - All fsk/fmv variables are &quot;untouchable&quot;.  To make it simple to test,
     we simply give them TcLevel=0.  This means that in a CTyVarEq, say,
       fmv ~ Int
     we NEVER unify fmv.

   - A unification flatten-skolem, fmv, ONLY gets unified when either
       a) The CFunEqCan takes a step, using an axiom
       b) By unflattenWanteds
    They are never unified in any other form of equality.
    For example [W] ffmv ~ Int  is stuck; it does not unify with fmv.

* We *never* substitute in the RHS (i.e. the fsk/fmv) of a CFunEqCan.
  That would destroy the invariant about the shape of a CFunEqCan,
  and it would risk wanted/wanted interactions. The only way we
  learn information about fsk is when the CFunEqCan takes a step.

  However we *do* substitute in the LHS of a CFunEqCan (else it
  would never get to fire!)

* Unflattening:
   - We unflatten Givens when leaving their scope (see unflattenGivens)
   - We unflatten Wanteds at the end of each attempt to simplify the
     wanteds; see unflattenWanteds, called from solveSimpleWanteds.

* Ownership of fsk/fmv.  Each canonical [G], [W], or [WD]
       CFunEqCan x : F xis ~ fsk/fmv
  &quot;owns&quot; a distinct evidence variable x, and flatten-skolem fsk/fmv.
  Why? We make a fresh fsk/fmv when the constraint is born;
  and we never rewrite the RHS of a CFunEqCan.

  In contrast a [D] CFunEqCan /shares/ its fmv with its partner [W],
  but does not &quot;own&quot; it.  If we reduce a [D] F Int ~ fmv, where
  say type instance F Int = ty, then we don't discharge fmv := ty.
  Rather we simply generate [D] fmv ~ ty (in GHC.Tc.Solver.Interact.reduce_top_fun_eq,
  and dischargeFmv)

* Inert set invariant: if F xis1 ~ fsk1, F xis2 ~ fsk2
                       then xis1 /= xis2
  i.e. at most one CFunEqCan with a particular LHS

* Flattening a type (F xis):
    - If we are flattening in a Wanted/Derived constraint
      then create new [W] x : F xis ~ fmv
      else create new [G] x : F xis ~ fsk
      with fresh evidence variable x and flatten-skolem fsk/fmv

    - Add it to the work list

    - Replace (F xis) with fsk/fmv in the type you are flattening

    - You can also add the CFunEqCan to the &quot;flat cache&quot;, which
      simply keeps track of all the function applications you
      have flattened.

    - If (F xis) is in the cache already, just
      use its fsk/fmv and evidence x, and emit nothing.

    - No need to substitute in the flat-cache. It's not the end
      of the world if we start with, say (F alpha ~ fmv1) and
      (F Int ~ fmv2) and then find alpha := Int.  Athat will
      simply give rise to fmv1 := fmv2 via [Interacting rule] below

* Canonicalising a CFunEqCan [G/W] x : F xis ~ fsk/fmv
    - Flatten xis (to substitute any tyvars; there are already no functions)
                  cos :: xis ~ flat_xis
    - New wanted  x2 :: F flat_xis ~ fsk/fmv
    - Add new wanted to flat cache
    - Discharge x = F cos ; x2

* [Interacting rule]
    (inert)     [W] x1 : F tys ~ fmv1
    (work item) [W] x2 : F tys ~ fmv2
  Just solve one from the other:
    x2 := x1
    fmv2 := fmv1
  This just unites the two fsks into one.
  Always solve given from wanted if poss.

* For top-level reductions, see Note [Top-level reductions for type functions]
  in GHC.Tc.Solver.Interact


Why given-fsks, alone, doesn't work
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could we get away with only flatten meta-tyvars, with no flatten-skolems? No.

  [W] w : alpha ~ [F alpha Int]

---&gt; flatten
  w = ...w'...
  [W] w' : alpha ~ [fsk]
  [G] &lt;F alpha Int&gt; : F alpha Int ~ fsk

--&gt; unify (no occurs check)
  alpha := [fsk]

But since fsk = F alpha Int, this is really an occurs check error.  If
that is all we know about alpha, we will succeed in constraint
solving, producing a program with an infinite type.

Even if we did finally get (g : fsk ~ Bool) by solving (F alpha Int ~ fsk)
using axiom, zonking would not see it, so (x::alpha) sitting in the
tree will get zonked to an infinite type.  (Zonking always only does
refl stuff.)

Why flatten-meta-vars, alone doesn't work
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Look at Simple13, with unification-fmvs only

  [G] g : a ~ [F a]

---&gt; Flatten given
  g' = g;[x]
  [G] g'  : a ~ [fmv]
  [W] x : F a ~ fmv

--&gt; subst a in x
  g' = g;[x]
  x = F g' ; x2
  [W] x2 : F [fmv] ~ fmv

And now we have an evidence cycle between g' and x!

If we used a given instead (ie current story)

  [G] g : a ~ [F a]

---&gt; Flatten given
  g' = g;[x]
  [G] g'  : a ~ [fsk]
  [G] &lt;F a&gt; : F a ~ fsk

---&gt; Substitute for a
  [G] g'  : a ~ [fsk]
  [G] F (sym g'); &lt;F a&gt; : F [fsk] ~ fsk


Why is it right to treat fmv's differently to ordinary unification vars?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  f :: forall a. a -&gt; a -&gt; Bool
  g :: F Int -&gt; F Int -&gt; Bool

Consider
  f (x:Int) (y:Bool)
This gives alpha~Int, alpha~Bool.  There is an inconsistency,
but really only one error.  SherLoc may tell you which location
is most likely, based on other occurrences of alpha.

Consider
  g (x:Int) (y:Bool)
Here we get (F Int ~ Int, F Int ~ Bool), which flattens to
  (fmv ~ Int, fmv ~ Bool)
But there are really TWO separate errors.

  ** We must not complain about Int~Bool. **

Moreover these two errors could arise in entirely unrelated parts of
the code.  (In the alpha case, there must be *some* connection (eg
v:alpha in common envt).)

Note [Unflattening can force the solver to iterate]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Look at #10340:
   type family Any :: *   -- No instances
   get :: MonadState s m =&gt; m s
   instance MonadState s (State s) where ...

   foo :: State Any Any
   foo = get

For 'foo' we instantiate 'get' at types mm ss
   [WD] MonadState ss mm, [WD] mm ss ~ State Any Any
Flatten, and decompose
   [WD] MonadState ss mm, [WD] Any ~ fmv
   [WD] mm ~ State fmv, [WD] fmv ~ ss
Unify mm := State fmv:
   [WD] MonadState ss (State fmv)
   [WD] Any ~ fmv, [WD] fmv ~ ss
Now we are stuck; the instance does not match!!  So unflatten:
   fmv := Any
   ss := Any    (*)
   [WD] MonadState Any (State Any)

The unification (*) represents progress, so we must do a second
round of solving; this time it succeeds. This is done by the 'go'
loop in solveSimpleWanteds.

This story does not feel right but it's the best I can do; and the
iteration only happens in pretty obscure circumstances.


************************************************************************
*                                                                      *
*                  Examples
     Here is a long series of examples I had to work through
*                                                                      *
************************************************************************

Simple20
~~~~~~~~
axiom F [a] = [F a]

 [G] F [a] ~ a
--&gt;
 [G] fsk ~ a
 [G] [F a] ~ fsk  (nc)
--&gt;
 [G] F a ~ fsk2
 [G] fsk ~ [fsk2]
 [G] fsk ~ a
--&gt;
 [G] F a ~ fsk2
 [G] a ~ [fsk2]
 [G] fsk ~ a

----------------------------------------
indexed-types/should_compile/T44984

  [W] H (F Bool) ~ H alpha
  [W] alpha ~ F Bool
--&gt;
  F Bool  ~ fmv0
  H fmv0  ~ fmv1
  H alpha ~ fmv2

  fmv1 ~ fmv2
  fmv0 ~ alpha

flatten
~~~~~~~
  fmv0  := F Bool
  fmv1  := H (F Bool)
  fmv2  := H alpha
  alpha := F Bool
plus
  fmv1 ~ fmv2

But these two are equal under the above assumptions.
Solve by Refl.


--- under plan B, namely solve fmv1:=fmv2 eagerly ---
  [W] H (F Bool) ~ H alpha
  [W] alpha ~ F Bool
--&gt;
  F Bool  ~ fmv0
  H fmv0  ~ fmv1
  H alpha ~ fmv2

  fmv1 ~ fmv2
  fmv0 ~ alpha
--&gt;
  F Bool  ~ fmv0
  H fmv0  ~ fmv1
  H alpha ~ fmv2    fmv2 := fmv1

  fmv0 ~ alpha

flatten
  fmv0 := F Bool
  fmv1 := H fmv0 = H (F Bool)
  retain   H alpha ~ fmv2
    because fmv2 has been filled
  alpha := F Bool


----------------------------
indexed-types/should_failt/T4179

after solving
  [W] fmv_1 ~ fmv_2
  [W] A3 (FCon x)           ~ fmv_1    (CFunEqCan)
  [W] A3 (x (aoa -&gt; fmv_2)) ~ fmv_2    (CFunEqCan)

----------------------------------------
indexed-types/should_fail/T7729a

a)  [W]   BasePrimMonad (Rand m) ~ m1
b)  [W]   tt m1 ~ BasePrimMonad (Rand m)

---&gt;  process (b) first
    BasePrimMonad (Ramd m) ~ fmv_atH
    fmv_atH ~ tt m1

---&gt;  now process (a)
    m1 ~ s_atH ~ tt m1    -- An obscure occurs check


----------------------------------------
typecheck/TcTypeNatSimple

Original constraint
  [W] x + y ~ x + alpha  (non-canonical)
==&gt;
  [W] x + y     ~ fmv1   (CFunEqCan)
  [W] x + alpha ~ fmv2   (CFuneqCan)
  [W] fmv1 ~ fmv2        (CTyEqCan)

(sigh)

----------------------------------------
indexed-types/should_fail/GADTwrong1

  [G] Const a ~ ()
==&gt; flatten
  [G] fsk ~ ()
  work item: Const a ~ fsk
==&gt; fire top rule
  [G] fsk ~ ()
  work item fsk ~ ()

Surely the work item should rewrite to () ~ ()?  Well, maybe not;
it'a very special case.  More generally, our givens look like
F a ~ Int, where (F a) is not reducible.


----------------------------------------
indexed_types/should_fail/T8227:

Why using a different can-rewrite rule in CFunEqCan heads
does not work.

Assuming NOT rewriting wanteds with wanteds

   Inert: [W] fsk_aBh ~ fmv_aBk -&gt; fmv_aBk
          [W] fmv_aBk ~ fsk_aBh

          [G] Scalar fsk_aBg ~ fsk_aBh
          [G] V a ~ f_aBg

   Worklist includes  [W] Scalar fmv_aBi ~ fmv_aBk
   fmv_aBi, fmv_aBk are flatten unification variables

   Work item: [W] V fsk_aBh ~ fmv_aBi

Note that the inert wanteds are cyclic, because we do not rewrite
wanteds with wanteds.


Then we go into a loop when normalise the work-item, because we
use rewriteOrSame on the argument of V.

Conclusion: Don't make canRewrite context specific; instead use
[W] a ~ ty to rewrite a wanted iff 'a' is a unification variable.


----------------------------------------

Here is a somewhat similar case:

   type family G a :: *

   blah :: (G a ~ Bool, Eq (G a)) =&gt; a -&gt; a
   blah = error &quot;urk&quot;

   foo x = blah x

For foo we get
   [W] Eq (G a), G a ~ Bool
Flattening
   [W] G a ~ fmv, Eq fmv, fmv ~ Bool
We can't simplify away the Eq Bool unless we substitute for fmv.
Maybe that doesn't matter: we would still be left with unsolved
G a ~ Bool.

--------------------------
#9318 has a very simple program leading to

  [W] F Int ~ Int
  [W] F Int ~ Bool

We don't want to get &quot;Error Int~Bool&quot;.  But if fmv's can rewrite
wanteds, we will

  [W] fmv ~ Int
  [W] fmv ~ Bool
---&gt;
  [W] Int ~ Bool


************************************************************************
*                                                                      *
*                FlattenEnv &amp; FlatM
*             The flattening environment &amp; monad
*                                                                      *
************************************************************************

-}</span><span>
</span><span id="line-455"></span><span>
</span><span id="line-456"></span><span class="hs-keyword">type</span><span> </span><span id="FlatWorkListRef"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatWorkListRef"><span class="hs-identifier hs-var">FlatWorkListRef</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcRef"><span class="hs-identifier hs-type">TcRef</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- See Note [The flattening work list]</span><span>
</span><span id="line-457"></span><span>
</span><span id="line-458"></span><span class="hs-keyword">data</span><span> </span><span id="FlattenEnv"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenEnv"><span class="hs-identifier hs-var">FlattenEnv</span></a></span></span><span>
</span><span id="line-459"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="FE"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FE"><span class="hs-identifier hs-var">FE</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="fe_mode"><span class="annot"><span class="annottext">FlattenEnv -&gt; FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#fe_mode"><span class="hs-identifier hs-var hs-var">fe_mode</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span>
</span><span id="line-460"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="fe_loc"><span class="annot"><span class="annottext">FlattenEnv -&gt; CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#fe_loc"><span class="hs-identifier hs-var hs-var">fe_loc</span></a></span></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtLoc"><span class="hs-identifier hs-type">CtLoc</span></a></span><span>              </span><span class="hs-comment">-- See Note [Flattener CtLoc]</span><span>
</span><span id="line-461"></span><span>                      </span><span class="hs-comment">-- unbanged because it's bogus in rewriteTyVar</span><span>
</span><span id="line-462"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="fe_flavour"><span class="annot"><span class="annottext">FlattenEnv -&gt; CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#fe_flavour"><span class="hs-identifier hs-var hs-var">fe_flavour</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavour"><span class="hs-identifier hs-type">CtFlavour</span></a></span><span>
</span><span id="line-463"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="fe_eq_rel"><span class="annot"><span class="annottext">FlattenEnv -&gt; EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#fe_eq_rel"><span class="hs-identifier hs-var hs-var">fe_eq_rel</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Core.Predicate.html#EqRel"><span class="hs-identifier hs-type">EqRel</span></a></span><span>             </span><span class="hs-comment">-- See Note [Flattener EqRels]</span><span>
</span><span id="line-464"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="fe_work"><span class="annot"><span class="annottext">FlattenEnv -&gt; FlatWorkListRef
</span><a href="GHC.Tc.Solver.Flatten.html#fe_work"><span class="hs-identifier hs-var hs-var">fe_work</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatWorkListRef"><span class="hs-identifier hs-type">FlatWorkListRef</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-comment">-- See Note [The flattening work list]</span><span>
</span><span id="line-465"></span><span>
</span><span id="line-466"></span><span class="hs-keyword">data</span><span> </span><span id="FlattenMode"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-var">FlattenMode</span></a></span></span><span>  </span><span class="hs-comment">-- Postcondition for all three: inert wrt the type substitution</span><span>
</span><span id="line-467"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="FM_FlattenAll"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span></span><span>          </span><span class="hs-comment">-- Postcondition: function-free</span><span>
</span><span id="line-468"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="FM_SubstOnly"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span></span><span>           </span><span class="hs-comment">-- See Note [Flattening under a forall]</span><span>
</span><span id="line-469"></span><span>
</span><span id="line-470"></span><span class="hs-comment">--  | FM_Avoid TcTyVar Bool  -- See Note [Lazy flattening]</span><span>
</span><span id="line-471"></span><span class="hs-comment">--                           -- Postcondition:</span><span>
</span><span id="line-472"></span><span class="hs-comment">--                           --  * tyvar is only mentioned in result under a rigid path</span><span>
</span><span id="line-473"></span><span class="hs-comment">--                           --    e.g.   [a] is ok, but F a won't happen</span><span>
</span><span id="line-474"></span><span class="hs-comment">--                           --  * If flat_top is True, top level is not a function application</span><span>
</span><span id="line-475"></span><span class="hs-comment">--                           --   (but under type constructors is ok e.g. [F a])</span><span>
</span><span id="line-476"></span><span>
</span><span id="line-477"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621681115341"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-478"></span><span>  </span><span id="local-6989586621681115339"><span class="annot"><span class="annottext">ppr :: FlattenMode -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;FM_FlattenAll&quot;</span></span><span>
</span><span id="line-479"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;FM_SubstOnly&quot;</span></span><span>
</span><span id="line-480"></span><span>
</span><span id="line-481"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#eqFlattenMode"><span class="hs-identifier hs-type">eqFlattenMode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-482"></span><span id="eqFlattenMode"><span class="annot"><span class="annottext">eqFlattenMode :: FlattenMode -&gt; FlattenMode -&gt; Bool
</span><a href="GHC.Tc.Solver.Flatten.html#eqFlattenMode"><span class="hs-identifier hs-var hs-var">eqFlattenMode</span></a></span></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-483"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#eqFlattenMode"><span class="hs-identifier hs-var">eqFlattenMode</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span>  </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-484"></span><span class="hs-comment">--  FM_Avoid tv1 b1 `eq` FM_Avoid tv2 b2 = tv1 == tv2 &amp;&amp; b1 == b2</span><span>
</span><span id="line-485"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#eqFlattenMode"><span class="hs-identifier hs-var">eqFlattenMode</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><span class="hs-identifier">_</span></span><span>  </span><span class="annot"><span class="annottext">FlattenMode
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-486"></span><span>
</span><span id="line-487"></span><span class="hs-comment">-- | The 'FlatM' monad is a wrapper around 'TcS' with the following</span><span>
</span><span id="line-488"></span><span class="hs-comment">-- extra capabilities: (1) it offers access to a 'FlattenEnv';</span><span>
</span><span id="line-489"></span><span class="hs-comment">-- and (2) it maintains the flattening worklist.</span><span>
</span><span id="line-490"></span><span class="hs-comment">-- See Note [The flattening work list].</span><span>
</span><span id="line-491"></span><span class="hs-keyword">newtype</span><span> </span><span id="FlatM"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span></span><span> </span><span id="local-6989586621681115743"><span class="annot"><a href="#local-6989586621681115743"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-492"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="FlatM"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="runFlatM"><span class="annot"><span class="annottext">forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenEnv"><span class="hs-identifier hs-type">FlattenEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115743"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-493"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115328"><span id="local-6989586621681115332"><span class="annot"><span class="annottext">(forall a b. (a -&gt; b) -&gt; FlatM a -&gt; FlatM b)
-&gt; (forall a b. a -&gt; FlatM b -&gt; FlatM a) -&gt; Functor FlatM
forall a b. a -&gt; FlatM b -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; FlatM a -&gt; FlatM b
forall (f :: * -&gt; *).
(forall a b. (a -&gt; b) -&gt; f a -&gt; f b)
-&gt; (forall a b. a -&gt; f b -&gt; f a) -&gt; Functor f
&lt;$ :: forall a b. a -&gt; FlatM b -&gt; FlatM a
$c&lt;$ :: forall a b. a -&gt; FlatM b -&gt; FlatM a
fmap :: forall a b. (a -&gt; b) -&gt; FlatM a -&gt; FlatM b
$cfmap :: forall a b. (a -&gt; b) -&gt; FlatM a -&gt; FlatM b
</span><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Functor</span></a></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-494"></span><span>
</span><span id="line-495"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621681115319"><span id="local-6989586621681115321"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-496"></span><span>  </span><span id="local-6989586621681115316"><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115316"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621681115315"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. FlatM a -&gt; (a -&gt; FlatM b) -&gt; FlatM b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621681115314"><span class="annot"><span class="annottext">a -&gt; FlatM b
</span><a href="#local-6989586621681115314"><span class="hs-identifier hs-var">k</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS b) -&gt; FlatM b
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS b) -&gt; FlatM b)
-&gt; (FlattenEnv -&gt; TcS b) -&gt; FlatM b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115313"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115313"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-497"></span><span>             </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115312"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115312"><span class="hs-identifier hs-var">a</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115316"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115313"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-498"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FlatM b -&gt; FlattenEnv -&gt; TcS b
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; FlatM b
</span><a href="#local-6989586621681115314"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115312"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115313"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-499"></span><span>
</span><span id="line-500"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621681115302"><span id="local-6989586621681115304"><span id="local-6989586621681115306"><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-501"></span><span>  </span><span id="local-6989586621681115298"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; FlatM a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621681115297"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115297"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcS a -&gt; FlattenEnv -&gt; TcS a
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; TcS a
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115297"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-502"></span><span>  </span><span id="local-6989586621681115294"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. FlatM (a -&gt; b) -&gt; FlatM a -&gt; FlatM b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatM (a -&gt; b) -&gt; FlatM a -&gt; FlatM b
forall (m :: * -&gt; *) a b. Monad m =&gt; m (a -&gt; b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#ap"><span class="hs-identifier hs-var">ap</span></a></span><span>
</span><span id="line-503"></span><span>
</span><span id="line-504"></span><span id="local-6989586621681115706"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-type">liftTcS</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115706"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115706"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-505"></span><span id="liftTcS"><span class="annot"><span class="annottext">liftTcS :: forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var hs-var">liftTcS</span></a></span></span><span> </span><span id="local-6989586621681115291"><span class="annot"><span class="annottext">TcS a
</span><a href="#local-6989586621681115291"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-506"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcS a -&gt; FlattenEnv -&gt; TcS a
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">TcS a
</span><a href="#local-6989586621681115291"><span class="hs-identifier hs-var">thing_inside</span></a></span><span>
</span><span id="line-507"></span><span>
</span><span id="line-508"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#emitFlatWork"><span class="hs-identifier hs-type">emitFlatWork</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-509"></span><span class="hs-comment">-- See Note [The flattening work list]</span><span>
</span><span id="line-510"></span><span id="emitFlatWork"><span class="annot"><span class="annottext">emitFlatWork :: Ct -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#emitFlatWork"><span class="hs-identifier hs-var hs-var">emitFlatWork</span></a></span></span><span> </span><span id="local-6989586621681115289"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681115289"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS ()) -&gt; FlatM ()
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS ()) -&gt; FlatM ())
-&gt; (FlattenEnv -&gt; TcS ()) -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115288"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115288"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FlatWorkListRef -&gt; ([Ct] -&gt; [Ct]) -&gt; TcS ()
forall a. TcRef a -&gt; (a -&gt; a) -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#updTcRef"><span class="hs-identifier hs-var">updTcRef</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenEnv -&gt; FlatWorkListRef
</span><a href="GHC.Tc.Solver.Flatten.html#fe_work"><span class="hs-identifier hs-var hs-var">fe_work</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115288"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681115289"><span class="hs-identifier hs-var">ct</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; [Ct] -&gt; [Ct]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="hs-special">)</span><span>
</span><span id="line-511"></span><span>
</span><span id="line-512"></span><span class="hs-comment">-- convenient wrapper when you have a CtEvidence describing</span><span>
</span><span id="line-513"></span><span class="hs-comment">-- the flattening operation</span><span>
</span><span id="line-514"></span><span id="local-6989586621681115701"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#runFlattenCtEv"><span class="hs-identifier hs-type">runFlattenCtEv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtEvidence"><span class="hs-identifier hs-type">CtEvidence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115701"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115701"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-515"></span><span id="runFlattenCtEv"><span class="annot"><span class="annottext">runFlattenCtEv :: forall a. FlattenMode -&gt; CtEvidence -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlattenCtEv"><span class="hs-identifier hs-var hs-var">runFlattenCtEv</span></a></span></span><span> </span><span id="local-6989586621681115285"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115285"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span id="local-6989586621681115284"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115284"><span class="hs-identifier hs-var">ev</span></a></span></span><span>
</span><span id="line-516"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
forall a.
FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-var">runFlatten</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115285"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; CtLoc
</span><a href="GHC.Tc.Types.Constraint.html#ctEvLoc"><span class="hs-identifier hs-var">ctEvLoc</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115284"><span class="hs-identifier hs-var">ev</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#ctEvFlavour"><span class="hs-identifier hs-var">ctEvFlavour</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115284"><span class="hs-identifier hs-var">ev</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; EqRel
</span><a href="GHC.Tc.Types.Constraint.html#ctEvEqRel"><span class="hs-identifier hs-var">ctEvEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115284"><span class="hs-identifier hs-var">ev</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-517"></span><span>
</span><span id="line-518"></span><span class="hs-comment">-- Run thing_inside (which does flattening), and put all</span><span>
</span><span id="line-519"></span><span class="hs-comment">-- the work it generates onto the main work list</span><span>
</span><span id="line-520"></span><span class="hs-comment">-- See Note [The flattening work list]</span><span>
</span><span id="line-521"></span><span id="local-6989586621681115699"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-type">runFlatten</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtLoc"><span class="hs-identifier hs-type">CtLoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavour"><span class="hs-identifier hs-type">CtFlavour</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html#EqRel"><span class="hs-identifier hs-type">EqRel</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115699"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115699"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-522"></span><span id="runFlatten"><span class="annot"><span class="annottext">runFlatten :: forall a.
FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-var hs-var">runFlatten</span></a></span></span><span> </span><span id="local-6989586621681115274"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115274"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span id="local-6989586621681115273"><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115273"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621681115272"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115272"><span class="hs-identifier hs-var">flav</span></a></span></span><span> </span><span id="local-6989586621681115271"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115271"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span id="local-6989586621681115270"><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115270"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-523"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115269"><span class="annot"><span class="annottext">FlatWorkListRef
</span><a href="#local-6989586621681115269"><span class="hs-identifier hs-var">flat_ref</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Ct] -&gt; TcS FlatWorkListRef
forall a. a -&gt; TcS (TcRef a)
</span><a href="GHC.Tc.Solver.Monad.html#newTcRef"><span class="hs-identifier hs-var">newTcRef</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-524"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681115267"><span class="annot"><span class="annottext">fmode :: FlattenEnv
</span><a href="#local-6989586621681115267"><span class="hs-identifier hs-var hs-var">fmode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FE :: FlattenMode
-&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatWorkListRef -&gt; FlattenEnv
</span><a href="GHC.Tc.Solver.Flatten.html#FE"><span class="hs-identifier hs-type">FE</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fe_mode :: FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#fe_mode"><span class="hs-identifier hs-var">fe_mode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115274"><span class="hs-identifier hs-var">mode</span></a></span><span>
</span><span id="line-525"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fe_loc :: CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#fe_loc"><span class="hs-identifier hs-var">fe_loc</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CtLoc -&gt; CtLoc
</span><a href="GHC.Tc.Types.Constraint.html#bumpCtLocDepth"><span class="hs-identifier hs-var">bumpCtLocDepth</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115273"><span class="hs-identifier hs-var">loc</span></a></span><span>
</span><span id="line-526"></span><span>                            </span><span class="hs-comment">-- See Note [Flatten when discharging CFunEqCan]</span><span>
</span><span id="line-527"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fe_flavour :: CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#fe_flavour"><span class="hs-identifier hs-var">fe_flavour</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115272"><span class="hs-identifier hs-var">flav</span></a></span><span>
</span><span id="line-528"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fe_eq_rel :: EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#fe_eq_rel"><span class="hs-identifier hs-var">fe_eq_rel</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115271"><span class="hs-identifier hs-var">eq_rel</span></a></span><span>
</span><span id="line-529"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fe_work :: FlatWorkListRef
</span><a href="GHC.Tc.Solver.Flatten.html#fe_work"><span class="hs-identifier hs-var">fe_work</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatWorkListRef
</span><a href="#local-6989586621681115269"><span class="hs-identifier hs-var">flat_ref</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-530"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115265"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115265"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115270"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115267"><span class="hs-identifier hs-var">fmode</span></a></span><span>
</span><span id="line-531"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115264"><span class="annot"><span class="annottext">[Ct]
</span><a href="#local-6989586621681115264"><span class="hs-identifier hs-var">new_flats</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatWorkListRef -&gt; TcS [Ct]
forall a. TcRef a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Monad.html#readTcRef"><span class="hs-identifier hs-var">readTcRef</span></a></span><span> </span><span class="annot"><span class="annottext">FlatWorkListRef
</span><a href="#local-6989586621681115269"><span class="hs-identifier hs-var">flat_ref</span></a></span><span>
</span><span id="line-532"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(WorkList -&gt; WorkList) -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#updWorkListTcS"><span class="hs-identifier hs-var">updWorkListTcS</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Ct] -&gt; WorkList -&gt; WorkList
</span><a href="#local-6989586621681115261"><span class="hs-identifier hs-var">add_flats</span></a></span><span> </span><span class="annot"><span class="annottext">[Ct]
</span><a href="#local-6989586621681115264"><span class="hs-identifier hs-var">new_flats</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-533"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">a -&gt; TcS a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115265"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-534"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-535"></span><span>    </span><span id="local-6989586621681115261"><span class="annot"><span class="annottext">add_flats :: [Ct] -&gt; WorkList -&gt; WorkList
</span><a href="#local-6989586621681115261"><span class="hs-identifier hs-var hs-var">add_flats</span></a></span></span><span> </span><span id="local-6989586621681115260"><span class="annot"><span class="annottext">[Ct]
</span><a href="#local-6989586621681115260"><span class="hs-identifier hs-var">new_flats</span></a></span></span><span> </span><span id="local-6989586621681115259"><span class="annot"><span class="annottext">WorkList
</span><a href="#local-6989586621681115259"><span class="hs-identifier hs-var">wl</span></a></span></span><span>
</span><span id="line-536"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WorkList
</span><a href="#local-6989586621681115259"><span class="hs-identifier hs-var">wl</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">wl_funeqs :: [Ct]
</span><a href="GHC.Tc.Solver.Monad.html#wl_funeqs"><span class="hs-identifier hs-var">wl_funeqs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Ct] -&gt; [Ct] -&gt; [Ct]
forall {a}. [a] -&gt; [a] -&gt; [a]
</span><a href="#local-6989586621681115257"><span class="hs-identifier hs-var">add_funeqs</span></a></span><span> </span><span class="annot"><span class="annottext">[Ct]
</span><a href="#local-6989586621681115260"><span class="hs-identifier hs-var">new_flats</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">WorkList -&gt; [Ct]
</span><a href="GHC.Tc.Solver.Monad.html#wl_funeqs"><span class="hs-identifier hs-var hs-var">wl_funeqs</span></a></span><span> </span><span class="annot"><span class="annottext">WorkList
</span><a href="#local-6989586621681115259"><span class="hs-identifier hs-var">wl</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-537"></span><span>
</span><span id="line-538"></span><span>    </span><span id="local-6989586621681115257"><span class="annot"><span class="annottext">add_funeqs :: [a] -&gt; [a] -&gt; [a]
</span><a href="#local-6989586621681115257"><span class="hs-identifier hs-var hs-var">add_funeqs</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span id="local-6989586621681115256"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115256"><span class="hs-identifier hs-var">wl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115256"><span class="hs-identifier hs-var">wl</span></a></span><span>
</span><span id="line-539"></span><span>    </span><span class="annot"><a href="#local-6989586621681115257"><span class="hs-identifier hs-var">add_funeqs</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115255"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115255"><span class="hs-identifier hs-var">f</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621681115254"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115254"><span class="hs-identifier hs-var">fs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681115253"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115253"><span class="hs-identifier hs-var">wl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a] -&gt; [a]
</span><a href="#local-6989586621681115257"><span class="hs-identifier hs-var">add_funeqs</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115254"><span class="hs-identifier hs-var">fs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621681115255"><span class="hs-identifier hs-var">f</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621681115253"><span class="hs-identifier hs-var">wl</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-540"></span><span>      </span><span class="hs-comment">-- add_funeqs fs ws = reverse fs ++ ws</span><span>
</span><span id="line-541"></span><span>      </span><span class="hs-comment">-- e.g. add_funeqs [f1,f2,f3] [w1,w2,w3,w4]</span><span>
</span><span id="line-542"></span><span>      </span><span class="hs-comment">--        = [f3,f2,f1,w1,w2,w3,w4]</span><span>
</span><span id="line-543"></span><span>
</span><span id="line-544"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-type">traceFlat</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-545"></span><span id="traceFlat"><span class="annot"><span class="annottext">traceFlat :: String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var hs-var">traceFlat</span></a></span></span><span> </span><span id="local-6989586621681115251"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621681115251"><span class="hs-identifier hs-var">herald</span></a></span></span><span> </span><span id="local-6989586621681115250"><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681115250"><span class="hs-identifier hs-var">doc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcS () -&gt; FlatM ()
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS () -&gt; FlatM ()) -&gt; TcS () -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621681115251"><span class="hs-identifier hs-var">herald</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621681115250"><span class="hs-identifier hs-var">doc</span></a></span><span>
</span><span id="line-546"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-pragma hs-type">traceFlat</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>  </span><span class="hs-comment">-- see Note [INLINE conditional tracing utilities]</span><span>
</span><span id="line-547"></span><span>
</span><span id="line-548"></span><span id="local-6989586621681115693"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-type">getFlatEnvField</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenEnv"><span class="hs-identifier hs-type">FlattenEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621681115693"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115693"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-549"></span><span id="getFlatEnvField"><span class="annot"><span class="annottext">getFlatEnvField :: forall a. (FlattenEnv -&gt; a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-var hs-var">getFlatEnvField</span></a></span></span><span> </span><span id="local-6989586621681115246"><span class="annot"><span class="annottext">FlattenEnv -&gt; a
</span><a href="#local-6989586621681115246"><span class="hs-identifier hs-var">accessor</span></a></span></span><span>
</span><span id="line-550"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115245"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115245"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; TcS a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenEnv -&gt; a
</span><a href="#local-6989586621681115246"><span class="hs-identifier hs-var">accessor</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115245"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-551"></span><span>
</span><span id="line-552"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-type">getEqRel</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html#EqRel"><span class="hs-identifier hs-type">EqRel</span></a></span><span>
</span><span id="line-553"></span><span id="getEqRel"><span class="annot"><span class="annottext">getEqRel :: FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var hs-var">getEqRel</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; EqRel) -&gt; FlatM EqRel
forall a. (FlattenEnv -&gt; a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-var">getFlatEnvField</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#fe_eq_rel"><span class="hs-identifier hs-var hs-var">fe_eq_rel</span></a></span><span>
</span><span id="line-554"></span><span>
</span><span id="line-555"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-type">getRole</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span>
</span><span id="line-556"></span><span id="getRole"><span class="annot"><span class="annottext">getRole :: FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var hs-var">getRole</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; Role
</span><a href="GHC.Core.Predicate.html#eqRelRole"><span class="hs-identifier hs-var">eqRelRole</span></a></span><span> </span><span class="annot"><span class="annottext">(EqRel -&gt; Role) -&gt; FlatM EqRel -&gt; FlatM Role
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-557"></span><span>
</span><span id="line-558"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getFlavour"><span class="hs-identifier hs-type">getFlavour</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavour"><span class="hs-identifier hs-type">CtFlavour</span></a></span><span>
</span><span id="line-559"></span><span id="getFlavour"><span class="annot"><span class="annottext">getFlavour :: FlatM CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavour"><span class="hs-identifier hs-var hs-var">getFlavour</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; CtFlavour) -&gt; FlatM CtFlavour
forall a. (FlattenEnv -&gt; a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-var">getFlatEnvField</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#fe_flavour"><span class="hs-identifier hs-var hs-var">fe_flavour</span></a></span><span>
</span><span id="line-560"></span><span>
</span><span id="line-561"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getFlavourRole"><span class="hs-identifier hs-type">getFlavourRole</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavourRole"><span class="hs-identifier hs-type">CtFlavourRole</span></a></span><span>
</span><span id="line-562"></span><span id="getFlavourRole"><span class="annot"><span class="annottext">getFlavourRole :: FlatM CtFlavourRole
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavourRole"><span class="hs-identifier hs-var hs-var">getFlavourRole</span></a></span></span><span>
</span><span id="line-563"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115238"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115238"><span class="hs-identifier hs-var">flavour</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavour"><span class="hs-identifier hs-var">getFlavour</span></a></span><span>
</span><span id="line-564"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115237"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115237"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-565"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">CtFlavourRole -&gt; FlatM CtFlavourRole
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115238"><span class="hs-identifier hs-var">flavour</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115237"><span class="hs-identifier hs-var">eq_rel</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-566"></span><span>
</span><span id="line-567"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getMode"><span class="hs-identifier hs-type">getMode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span>
</span><span id="line-568"></span><span id="getMode"><span class="annot"><span class="annottext">getMode :: FlatM FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#getMode"><span class="hs-identifier hs-var hs-var">getMode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; FlattenMode) -&gt; FlatM FlattenMode
forall a. (FlattenEnv -&gt; a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-var">getFlatEnvField</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#fe_mode"><span class="hs-identifier hs-var hs-var">fe_mode</span></a></span><span>
</span><span id="line-569"></span><span>
</span><span id="line-570"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#getLoc"><span class="hs-identifier hs-type">getLoc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtLoc"><span class="hs-identifier hs-type">CtLoc</span></a></span><span>
</span><span id="line-571"></span><span id="getLoc"><span class="annot"><span class="annottext">getLoc :: FlatM CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#getLoc"><span class="hs-identifier hs-var hs-var">getLoc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; CtLoc) -&gt; FlatM CtLoc
forall a. (FlattenEnv -&gt; a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#getFlatEnvField"><span class="hs-identifier hs-var">getFlatEnvField</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#fe_loc"><span class="hs-identifier hs-var hs-var">fe_loc</span></a></span><span>
</span><span id="line-572"></span><span>
</span><span id="line-573"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#checkStackDepth"><span class="hs-identifier hs-type">checkStackDepth</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-574"></span><span id="checkStackDepth"><span class="annot"><span class="annottext">checkStackDepth :: TcType -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#checkStackDepth"><span class="hs-identifier hs-var hs-var">checkStackDepth</span></a></span></span><span> </span><span id="local-6989586621681115232"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115232"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-575"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115231"><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115231"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#getLoc"><span class="hs-identifier hs-var">getLoc</span></a></span><span>
</span><span id="line-576"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcS () -&gt; FlatM ()
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS () -&gt; FlatM ()) -&gt; TcS () -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#checkReductionDepth"><span class="hs-identifier hs-var">checkReductionDepth</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115231"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115232"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-577"></span><span>
</span><span id="line-578"></span><span class="hs-comment">-- | Change the 'EqRel' in a 'FlatM'.</span><span>
</span><span id="line-579"></span><span id="local-6989586621681115686"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-type">setEqRel</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html#EqRel"><span class="hs-identifier hs-type">EqRel</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115686"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115686"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-580"></span><span id="setEqRel"><span class="annot"><span class="annottext">setEqRel :: forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var hs-var">setEqRel</span></a></span></span><span> </span><span id="local-6989586621681115227"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115227"><span class="hs-identifier hs-var">new_eq_rel</span></a></span></span><span> </span><span id="local-6989586621681115226"><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115226"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-581"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115225"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115225"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-582"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115227"><span class="hs-identifier hs-var">new_eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; EqRel -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#fe_eq_rel"><span class="hs-identifier hs-var hs-var">fe_eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115225"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-583"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115226"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115225"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-584"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115226"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115225"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fe_eq_rel :: EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#fe_eq_rel"><span class="hs-identifier hs-var">fe_eq_rel</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681115227"><span class="hs-identifier hs-var">new_eq_rel</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-585"></span><span>
</span><span id="line-586"></span><span class="hs-comment">-- | Change the 'FlattenMode' in a 'FlattenEnv'.</span><span>
</span><span id="line-587"></span><span id="local-6989586621681115683"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#setMode"><span class="hs-identifier hs-type">setMode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115683"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115683"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-588"></span><span id="setMode"><span class="annot"><span class="annottext">setMode :: forall a. FlattenMode -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setMode"><span class="hs-identifier hs-var hs-var">setMode</span></a></span></span><span> </span><span id="local-6989586621681115223"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115223"><span class="hs-identifier hs-var">new_mode</span></a></span></span><span> </span><span id="local-6989586621681115222"><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115222"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-589"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115221"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115221"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-590"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115223"><span class="hs-identifier hs-var">new_mode</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode -&gt; FlattenMode -&gt; Bool
</span><a href="GHC.Tc.Solver.Flatten.html#eqFlattenMode"><span class="hs-operator hs-var">`eqFlattenMode`</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#fe_mode"><span class="hs-identifier hs-var hs-var">fe_mode</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115221"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-591"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115222"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115221"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-592"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115222"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115221"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fe_mode :: FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#fe_mode"><span class="hs-identifier hs-var">fe_mode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115223"><span class="hs-identifier hs-var">new_mode</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-593"></span><span>
</span><span id="line-594"></span><span class="hs-comment">-- | Make sure that flattening actually produces a coercion (in other</span><span>
</span><span id="line-595"></span><span class="hs-comment">-- words, make sure our flavour is not Derived)</span><span>
</span><span id="line-596"></span><span class="hs-comment">-- Note [No derived kind equalities]</span><span>
</span><span id="line-597"></span><span id="local-6989586621681115681"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#noBogusCoercions"><span class="hs-identifier hs-type">noBogusCoercions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115681"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115681"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-598"></span><span id="noBogusCoercions"><span class="annot"><span class="annottext">noBogusCoercions :: forall a. FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#noBogusCoercions"><span class="hs-identifier hs-var hs-var">noBogusCoercions</span></a></span></span><span> </span><span id="local-6989586621681115219"><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115219"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span>
</span><span id="line-599"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115218"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115218"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-600"></span><span>    </span><span class="hs-comment">-- No new thunk is made if the flavour hasn't changed (note the bang).</span><span>
</span><span id="line-601"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621681115217"><span class="annot"><span class="annottext">env' :: FlattenEnv
</span><a href="#local-6989586621681115217"><span class="hs-identifier hs-var hs-var">env'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#fe_flavour"><span class="hs-identifier hs-var hs-var">fe_flavour</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115218"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-602"></span><span>          </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Derived"><span class="hs-identifier hs-var">Derived</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115218"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fe_flavour :: CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#fe_flavour"><span class="hs-identifier hs-var">fe_flavour</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ShadowInfo -&gt; CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Wanted"><span class="hs-identifier hs-var">Wanted</span></a></span><span> </span><span class="annot"><span class="annottext">ShadowInfo
</span><a href="GHC.Tc.Types.Constraint.html#WDeriv"><span class="hs-identifier hs-var">WDeriv</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-603"></span><span>          </span><span class="annot"><span class="annottext">CtFlavour
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115218"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-604"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-605"></span><span>    </span><span class="annot"><span class="annottext">FlatM a -&gt; FlattenEnv -&gt; TcS a
forall a. FlatM a -&gt; FlattenEnv -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatM"><span class="hs-identifier hs-var hs-var">runFlatM</span></a></span><span> </span><span class="annot"><span class="annottext">FlatM a
</span><a href="#local-6989586621681115219"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115217"><span class="hs-identifier hs-var">env'</span></a></span><span>
</span><span id="line-606"></span><span>
</span><span id="line-607"></span><span id="local-6989586621681115213"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#bumpDepth"><span class="hs-identifier hs-type">bumpDepth</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115213"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621681115213"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-608"></span><span id="bumpDepth"><span class="annot"><span class="annottext">bumpDepth :: forall a. FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#bumpDepth"><span class="hs-identifier hs-var hs-var">bumpDepth</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span id="local-6989586621681115211"><span class="annot"><span class="annottext">FlattenEnv -&gt; TcS a
</span><a href="#local-6989586621681115211"><span class="hs-identifier hs-var">thing_inside</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-609"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a. (FlattenEnv -&gt; TcS a) -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-var">FlatM</span></a></span><span> </span><span class="annot"><span class="annottext">((FlattenEnv -&gt; TcS a) -&gt; FlatM a)
-&gt; (FlattenEnv -&gt; TcS a) -&gt; FlatM a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621681115210"><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115210"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-610"></span><span>      </span><span class="hs-comment">-- bumpDepth can be called a lot during flattening so we force the</span><span>
</span><span id="line-611"></span><span>      </span><span class="hs-comment">-- new env to avoid accumulating thunks.</span><span>
</span><span id="line-612"></span><span>      </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621681115209"><span class="annot"><span class="annottext">env' :: FlattenEnv
</span><a href="#local-6989586621681115209"><span class="hs-identifier hs-var hs-var">env'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115210"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fe_loc :: CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#fe_loc"><span class="hs-identifier hs-var">fe_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CtLoc -&gt; CtLoc
</span><a href="GHC.Tc.Types.Constraint.html#bumpCtLocDepth"><span class="hs-identifier hs-var">bumpCtLocDepth</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenEnv -&gt; CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#fe_loc"><span class="hs-identifier hs-var hs-var">fe_loc</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115210"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-613"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FlattenEnv -&gt; TcS a
</span><a href="#local-6989586621681115211"><span class="hs-identifier hs-var">thing_inside</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenEnv
</span><a href="#local-6989586621681115209"><span class="hs-identifier hs-var">env'</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-614"></span><span>
</span><span id="line-615"></span><span class="hs-comment">{-
Note [The flattening work list]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The &quot;flattening work list&quot;, held in the fe_work field of FlattenEnv,
is a list of CFunEqCans generated during flattening.  The key idea
is this.  Consider flattening (Eq (F (G Int) (H Bool)):
  * The flattener recursively calls itself on sub-terms before building
    the main term, so it will encounter the terms in order
              G Int
              H Bool
              F (G Int) (H Bool)
    flattening to sub-goals
              w1: G Int ~ fuv0
              w2: H Bool ~ fuv1
              w3: F fuv0 fuv1 ~ fuv2

  * Processing w3 first is BAD, because we can't reduce i t,so it'll
    get put into the inert set, and later kicked out when w1, w2 are
    solved.  In #9872 this led to inert sets containing hundreds
    of suspended calls.

  * So we want to process w1, w2 first.

  * So you might think that we should just use a FIFO deque for the work-list,
    so that putting adding goals in order w1,w2,w3 would mean we processed
    w1 first.

  * BUT suppose we have 'type instance G Int = H Char'.  Then processing
    w1 leads to a new goal
                w4: H Char ~ fuv0
    We do NOT want to put that on the far end of a deque!  Instead we want
    to put it at the *front* of the work-list so that we continue to work
    on it.

So the work-list structure is this:

  * The wl_funeqs (in TcS) is a LIFO stack; we push new goals (such as w4) on
    top (extendWorkListFunEq), and take new work from the top
    (selectWorkItem).

  * When flattening, emitFlatWork pushes new flattening goals (like
    w1,w2,w3) onto the flattening work list, fe_work, another
    push-down stack.

  * When we finish flattening, we *reverse* the fe_work stack
    onto the wl_funeqs stack (which brings w1 to the top).

The function runFlatten initialises the fe_work stack, and reverses
it onto wl_fun_eqs at the end.

Note [Flattener EqRels]
~~~~~~~~~~~~~~~~~~~~~~~
When flattening, we need to know which equality relation -- nominal
or representation -- we should be respecting. The only difference is
that we rewrite variables by representational equalities when fe_eq_rel
is ReprEq, and that we unwrap newtypes when flattening w.r.t.
representational equality.

Note [Flattener CtLoc]
~~~~~~~~~~~~~~~~~~~~~~
The flattener does eager type-family reduction.
Type families might loop, and we
don't want GHC to do so. A natural solution is to have a bounded depth
to these processes. A central difficulty is that such a solution isn't
quite compositional. For example, say it takes F Int 10 steps to get to Bool.
How many steps does it take to get from F Int -&gt; F Int to Bool -&gt; Bool?
10? 20? What about getting from Const Char (F Int) to Char? 11? 1? Hard to
know and hard to track. So, we punt, essentially. We store a CtLoc in
the FlattenEnv and just update the environment when recurring. In the
TyConApp case, where there may be multiple type families to flatten,
we just copy the current CtLoc into each branch. If any branch hits the
stack limit, then the whole thing fails.

A consequence of this is that setting the stack limits appropriately
will be essentially impossible. So, the official recommendation if a
stack limit is hit is to disable the check entirely. Otherwise, there
will be baffling, unpredictable errors.

Note [Lazy flattening]
~~~~~~~~~~~~~~~~~~~~~~
The idea of FM_Avoid mode is to flatten less aggressively.  If we have
       a ~ [F Int]
there seems to be no great merit in lifting out (F Int).  But if it was
       a ~ [G a Int]
then we *do* want to lift it out, in case (G a Int) reduces to Bool, say,
which gets rid of the occurs-check problem.  (For the flat_top Bool, see
comments above and at call sites.)

HOWEVER, the lazy flattening actually seems to make type inference go
*slower*, not faster.  perf/compiler/T3064 is a case in point; it gets
*dramatically* worse with FM_Avoid.  I think it may be because
floating the types out means we normalise them, and that often makes
them smaller and perhaps allows more re-use of previously solved
goals.  But to be honest I'm not absolutely certain, so I am leaving
FM_Avoid in the code base.  What I'm removing is the unique place
where it is *used*, namely in GHC.Tc.Solver.Canonical.canEqTyVar.

See also Note [Conservative unification check] in GHC.Tc.Utils.Unify, which gives
other examples where lazy flattening caused problems.

Bottom line: FM_Avoid is unused for now (Nov 14).
Note: T5321Fun got faster when I disabled FM_Avoid
      T5837 did too, but it's pathological anyway

Note [Phantoms in the flattener]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we have

data Proxy p = Proxy

and we're flattening (Proxy ty) w.r.t. ReprEq. Then, we know that `ty`
is really irrelevant -- it will be ignored when solving for representational
equality later on. So, we omit flattening `ty` entirely. This may
violate the expectation of &quot;xi&quot;s for a bit, but the canonicaliser will
soon throw out the phantoms when decomposing a TyConApp. (Or, the
canonicaliser will emit an insoluble, in which case the unflattened version
yields a better error message anyway.)

Note [No derived kind equalities]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A kind-level coercion can appear in types, via mkCastTy. So, whenever
we are generating a coercion in a dependent context (in other words,
in a kind) we need to make sure that our flavour is never Derived
(as Derived constraints have no evidence). The noBogusCoercions function
changes the flavour from Derived just for this purpose.

-}</span><span>
</span><span id="line-742"></span><span>
</span><span id="line-743"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
*      Externally callable flattening functions                        *
*                                                                      *
*  They are all wrapped in runFlatten, so their                        *
*  flattening work gets put into the work list                         *
*                                                                      *
*********************************************************************

Note [rewriteTyVar]
~~~~~~~~~~~~~~~~~~~~~~
Suppose we have an injective function F and
  inert_funeqs:   F t1 ~ fsk1
                  F t2 ~ fsk2
  inert_eqs:      fsk1 ~ [a]
                  a ~ Int
                  fsk2 ~ [Int]

We never rewrite the RHS (cc_fsk) of a CFunEqCan. But we /do/ want to get the
[D] t1 ~ t2 from the injectiveness of F. So we flatten cc_fsk of CFunEqCans
when trying to find derived equalities arising from injectivity.
-}</span><span>
</span><span id="line-765"></span><span>
</span><span id="line-766"></span><span class="hs-comment">-- | See Note [Flattening].</span><span>
</span><span id="line-767"></span><span class="hs-comment">-- If (xi, co) &lt;- flatten mode ev ty, then co :: xi ~r ty</span><span>
</span><span id="line-768"></span><span class="hs-comment">-- where r is the role in @ev@. If @mode@ is 'FM_FlattenAll',</span><span>
</span><span id="line-769"></span><span class="hs-comment">-- then 'xi' is almost function-free (Note [Almost function-free]</span><span>
</span><span id="line-770"></span><span class="hs-comment">-- in &quot;GHC.Tc.Types&quot;).</span><span>
</span><span id="line-771"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten"><span class="hs-identifier hs-type">flatten</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenMode"><span class="hs-identifier hs-type">FlattenMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtEvidence"><span class="hs-identifier hs-type">CtEvidence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span>
</span><span id="line-772"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-773"></span><span id="flatten"><span class="annot"><span class="annottext">flatten :: FlattenMode -&gt; CtEvidence -&gt; TcType -&gt; TcS (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten"><span class="hs-identifier hs-var hs-var">flatten</span></a></span></span><span> </span><span id="local-6989586621681115206"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115206"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span id="local-6989586621681115205"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115205"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span id="local-6989586621681115204"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115204"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-774"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten {&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenMode -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115206"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115204"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-775"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115202"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115202"><span class="hs-identifier hs-var">ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115201"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115201"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; CtEvidence
-&gt; FlatM (TcType, CoercionN)
-&gt; TcS (TcType, CoercionN)
forall a. FlattenMode -&gt; CtEvidence -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlattenCtEv"><span class="hs-identifier hs-var">runFlattenCtEv</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115206"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115205"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115204"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-776"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten }&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115202"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-777"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; TcS (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115202"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115201"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-778"></span><span>
</span><span id="line-779"></span><span class="hs-comment">-- Apply the inert set as an *inert generalised substitution* to</span><span>
</span><span id="line-780"></span><span class="hs-comment">-- a variable, zonking along the way.</span><span>
</span><span id="line-781"></span><span class="hs-comment">-- See Note [inert_eqs: the inert equalities] in GHC.Tc.Solver.Monad.</span><span>
</span><span id="line-782"></span><span class="hs-comment">-- Equivalently, this flattens the variable with respect to NomEq</span><span>
</span><span id="line-783"></span><span class="hs-comment">-- in a Derived constraint. (Why Derived? Because Derived allows the</span><span>
</span><span id="line-784"></span><span class="hs-comment">-- most about of rewriting.) Returns no coercion, because we're</span><span>
</span><span id="line-785"></span><span class="hs-comment">-- using Derived constraints.</span><span>
</span><span id="line-786"></span><span class="hs-comment">-- See Note [rewriteTyVar]</span><span>
</span><span id="line-787"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#rewriteTyVar"><span class="hs-identifier hs-type">rewriteTyVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span>
</span><span id="line-788"></span><span id="rewriteTyVar"><span class="annot"><span class="annottext">rewriteTyVar :: TcTyVar -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Flatten.html#rewriteTyVar"><span class="hs-identifier hs-var hs-var">rewriteTyVar</span></a></span></span><span> </span><span id="local-6989586621681115199"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115199"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-789"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;rewriteTyVar {&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115199"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-790"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115198"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115198"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; CtLoc
-&gt; CtFlavour
-&gt; EqRel
-&gt; FlatM (TcType, CoercionN)
-&gt; TcS (TcType, CoercionN)
forall a.
FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-var">runFlatten</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
forall {a}. a
</span><a href="#local-6989586621681115197"><span class="hs-identifier hs-var">fake_loc</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Derived"><span class="hs-identifier hs-var">Derived</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; TcS (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; TcS (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-791"></span><span>                    </span><span class="annot"><span class="annottext">TcTyVar -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flattenTyVar"><span class="hs-identifier hs-var">flattenTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115199"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-792"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;rewriteTyVar }&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115198"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-793"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115198"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-794"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-795"></span><span>    </span><span id="local-6989586621681115197"><span class="annot"><span class="annottext">fake_loc :: a
</span><a href="#local-6989586621681115197"><span class="hs-identifier hs-var hs-var">fake_loc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; a
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;rewriteTyVar used a CtLoc&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115199"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-796"></span><span>
</span><span id="line-797"></span><span class="hs-comment">-- specialized to flattening kinds: never Derived, always Nominal</span><span>
</span><span id="line-798"></span><span class="hs-comment">-- See Note [No derived kind equalities]</span><span>
</span><span id="line-799"></span><span class="hs-comment">-- See Note [Flattening]</span><span>
</span><span id="line-800"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenKind"><span class="hs-identifier hs-type">flattenKind</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtLoc"><span class="hs-identifier hs-type">CtLoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavour"><span class="hs-identifier hs-type">CtFlavour</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercionN"><span class="hs-identifier hs-type">TcCoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-801"></span><span id="flattenKind"><span class="annot"><span class="annottext">flattenKind :: CtLoc -&gt; CtFlavour -&gt; TcType -&gt; TcS (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flattenKind"><span class="hs-identifier hs-var hs-var">flattenKind</span></a></span></span><span> </span><span id="local-6989586621681115189"><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115189"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621681115188"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115188"><span class="hs-identifier hs-var">flav</span></a></span></span><span> </span><span id="local-6989586621681115187"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115187"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-802"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flattenKind {&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtFlavour -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115188"><span class="hs-identifier hs-var">flav</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115187"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-803"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681115186"><span class="annot"><span class="annottext">flav' :: CtFlavour
</span><a href="#local-6989586621681115186"><span class="hs-identifier hs-var hs-var">flav'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115188"><span class="hs-identifier hs-var">flav</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-804"></span><span>                       </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Derived"><span class="hs-identifier hs-var">Derived</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ShadowInfo -&gt; CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Wanted"><span class="hs-identifier hs-var">Wanted</span></a></span><span> </span><span class="annot"><span class="annottext">ShadowInfo
</span><a href="GHC.Tc.Types.Constraint.html#WDeriv"><span class="hs-identifier hs-var">WDeriv</span></a></span><span>  </span><span class="hs-comment">-- the WDeriv/WOnly choice matters not</span><span>
</span><span id="line-805"></span><span>                       </span><span class="annot"><span class="annottext">CtFlavour
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115188"><span class="hs-identifier hs-var">flav</span></a></span><span>
</span><span id="line-806"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115185"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115185"><span class="hs-identifier hs-var">ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115184"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115184"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; CtLoc
-&gt; CtFlavour
-&gt; EqRel
-&gt; FlatM (TcType, CoercionN)
-&gt; TcS (TcType, CoercionN)
forall a.
FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-var">runFlatten</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115189"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681115186"><span class="hs-identifier hs-var">flav'</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115187"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-807"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flattenKind }&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115185"><span class="hs-identifier hs-var">ty'</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115184"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- co is never a panic</span><span>
</span><span id="line-808"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; TcS (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115185"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115184"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-809"></span><span>
</span><span id="line-810"></span><span class="hs-comment">-- See Note [Flattening]</span><span>
</span><span id="line-811"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenArgsNom"><span class="hs-identifier hs-type">flattenArgsNom</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtEvidence"><span class="hs-identifier hs-type">CtEvidence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercion"><span class="hs-identifier hs-type">TcCoercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#TcCoercionN"><span class="hs-identifier hs-type">TcCoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-812"></span><span class="hs-comment">-- Externally-callable, hence runFlatten</span><span>
</span><span id="line-813"></span><span class="hs-comment">-- Flatten a vector of types all at once; in fact they are</span><span>
</span><span id="line-814"></span><span class="hs-comment">-- always the arguments of type family or class, so</span><span>
</span><span id="line-815"></span><span class="hs-comment">--      ctEvFlavour ev = Nominal</span><span>
</span><span id="line-816"></span><span class="hs-comment">-- and we want to flatten all at nominal role</span><span>
</span><span id="line-817"></span><span class="hs-comment">-- The kind passed in is the kind of the type family or class, call it T</span><span>
</span><span id="line-818"></span><span class="hs-comment">-- The last coercion returned has type (tcTypeKind(T xis) ~N tcTypeKind(T tys))</span><span>
</span><span id="line-819"></span><span class="hs-comment">--</span><span>
</span><span id="line-820"></span><span class="hs-comment">-- For Derived constraints the returned coercion may be undefined</span><span>
</span><span id="line-821"></span><span class="hs-comment">-- because flattening may use a Derived equality ([D] a ~ ty)</span><span>
</span><span id="line-822"></span><span id="flattenArgsNom"><span class="annot"><span class="annottext">flattenArgsNom :: CtEvidence
-&gt; TyCon -&gt; [TcType] -&gt; TcS ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flattenArgsNom"><span class="hs-identifier hs-var hs-var">flattenArgsNom</span></a></span></span><span> </span><span id="local-6989586621681115182"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115182"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span id="local-6989586621681115181"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115181"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681115180"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115180"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-823"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten_args {&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TcType -&gt; SDoc) -&gt; [TcType] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115180"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-824"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115178"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115178"><span class="hs-identifier hs-var">tys'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115177"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115177"><span class="hs-identifier hs-var">cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115176"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115176"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-825"></span><span>           </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; CtEvidence
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
-&gt; TcS ([TcType], [CoercionN], CoercionN)
forall a. FlattenMode -&gt; CtEvidence -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlattenCtEv"><span class="hs-identifier hs-var">runFlattenCtEv</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681115182"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-identifier hs-var">flatten_args_tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115181"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; [Role]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115180"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-826"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten }&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TcType -&gt; SDoc) -&gt; [TcType] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115178"><span class="hs-identifier hs-var">tys'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-827"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcType], [CoercionN], CoercionN)
-&gt; TcS ([TcType], [CoercionN], CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115178"><span class="hs-identifier hs-var">tys'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115177"><span class="hs-identifier hs-var">cos</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115176"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-828"></span><span>
</span><span id="line-829"></span><span class="hs-comment">-- | Flatten a type w.r.t. nominal equality. This is useful to rewrite</span><span>
</span><span id="line-830"></span><span class="hs-comment">-- a type w.r.t. any givens. It does not do type-family reduction. This</span><span>
</span><span id="line-831"></span><span class="hs-comment">-- will never emit new constraints. Call this when the inert set contains</span><span>
</span><span id="line-832"></span><span class="hs-comment">-- only givens.</span><span>
</span><span id="line-833"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenType"><span class="hs-identifier hs-type">flattenType</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtLoc"><span class="hs-identifier hs-type">CtLoc</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span>
</span><span id="line-834"></span><span id="flattenType"><span class="annot"><span class="annottext">flattenType :: CtLoc -&gt; TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Flatten.html#flattenType"><span class="hs-identifier hs-var hs-var">flattenType</span></a></span></span><span> </span><span id="local-6989586621681115172"><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115172"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621681115171"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115171"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-835"></span><span>          </span><span class="hs-comment">-- More info about FM_SubstOnly in Note [Holes] in GHC.Tc.Types.Constraint</span><span>
</span><span id="line-836"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115170"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115170"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; CtLoc
-&gt; CtFlavour
-&gt; EqRel
-&gt; FlatM (TcType, CoercionN)
-&gt; TcS (TcType, CoercionN)
forall a.
FlattenMode -&gt; CtLoc -&gt; CtFlavour -&gt; EqRel -&gt; FlatM a -&gt; TcS a
</span><a href="GHC.Tc.Solver.Flatten.html#runFlatten"><span class="hs-identifier hs-var">runFlatten</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681115172"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#Given"><span class="hs-identifier hs-var">Given</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; TcS (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; TcS (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-837"></span><span>                    </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115171"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-838"></span><span>                     </span><span class="hs-comment">-- use Given flavor so that it is rewritten</span><span>
</span><span id="line-839"></span><span>                     </span><span class="hs-comment">-- only w.r.t. Givens, never Wanteds/Deriveds</span><span>
</span><span id="line-840"></span><span>                     </span><span class="hs-comment">-- (Shouldn't matter, if only Givens are present</span><span>
</span><span id="line-841"></span><span>                     </span><span class="hs-comment">-- anyway)</span><span>
</span><span id="line-842"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115170"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-843"></span><span>
</span><span id="line-844"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
*           The main flattening functions
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-849"></span><span>
</span><span id="line-850"></span><span class="hs-comment">{- Note [Flattening]
~~~~~~~~~~~~~~~~~~~~
  flatten ty  ==&gt;   (xi, co)
    where
      xi has no type functions, unless they appear under ForAlls
         has no skolems that are mapped in the inert set
         has no filled-in metavariables
      co :: xi ~ ty

Key invariants:
  (F0) co :: xi ~ zonk(ty)
  (F1) tcTypeKind(xi) succeeds and returns a fully zonked kind
  (F2) tcTypeKind(xi) `eqType` zonk(tcTypeKind(ty))

Note that it is flatten's job to flatten *every type function it sees*.
flatten is only called on *arguments* to type functions, by canEqGiven.

Flattening also:
  * zonks, removing any metavariables, and
  * applies the substitution embodied in the inert set

The result of flattening is *almost function-free*. See
Note [Almost function-free] in GHC.Tc.Utils.

Because flattening zonks and the returned coercion (&quot;co&quot; above) is also
zonked, it's possible that (co :: xi ~ ty) isn't quite true. So, instead,
we can rely on this fact:

  (F0) co :: xi ~ zonk(ty)

Note that the left-hand type of co is *always* precisely xi. The right-hand
type may or may not be ty, however: if ty has unzonked filled-in metavariables,
then the right-hand type of co will be the zonked version of ty.
It is for this reason that we
occasionally have to explicitly zonk, when (co :: xi ~ ty) is important
even before we zonk the whole program. For example, see the FTRNotFollowed
case in flattenTyVar.

Why have these invariants on flattening? Because we sometimes use tcTypeKind
during canonicalisation, and we want this kind to be zonked (e.g., see
GHC.Tc.Solver.Canonical.canEqTyVar).

Flattening is always homogeneous. That is, the kind of the result of flattening is
always the same as the kind of the input, modulo zonking. More formally:

  (F2) tcTypeKind(xi) `eqType` zonk(tcTypeKind(ty))

This invariant means that the kind of a flattened type might not itself be flat.

Recall that in comments we use alpha[flat = ty] to represent a
flattening skolem variable alpha which has been generated to stand in
for ty.

----- Example of flattening a constraint: ------
  flatten (List (F (G Int)))  ==&gt;  (xi, cc)
    where
      xi  = List alpha
      cc  = { G Int ~ beta[flat = G Int],
              F beta ~ alpha[flat = F beta] }
Here
  * alpha and beta are 'flattening skolem variables'.
  * All the constraints in cc are 'given', and all their coercion terms
    are the identity.

NB: Flattening Skolems only occur in canonical constraints, which
are never zonked, so we don't need to worry about zonking doing
accidental unflattening.

Note that we prefer to leave type synonyms unexpanded when possible,
so when the flattener encounters one, it first asks whether its
transitive expansion contains any type function applications.  If so,
it expands the synonym and proceeds; if not, it simply returns the
unexpanded synonym.

Note [flatten_args performance]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In programs with lots of type-level evaluation, flatten_args becomes
part of a tight loop. For example, see test perf/compiler/T9872a, which
calls flatten_args a whopping 7,106,808 times. It is thus important
that flatten_args be efficient.

Performance testing showed that the current implementation is indeed
efficient. It's critically important that zipWithAndUnzipM be
specialized to TcS, and it's also quite helpful to actually `inline`
it. On test T9872a, here are the allocation stats (Dec 16, 2014):

 * Unspecialized, uninlined:     8,472,613,440 bytes allocated in the heap
 * Specialized, uninlined:       6,639,253,488 bytes allocated in the heap
 * Specialized, inlined:         6,281,539,792 bytes allocated in the heap

To improve performance even further, flatten_args_nom is split off
from flatten_args, as nominal equality is the common case. This would
be natural to write using mapAndUnzipM, but even inlined, that function
is not as performant as a hand-written loop.

 * mapAndUnzipM, inlined:        7,463,047,432 bytes allocated in the heap
 * hand-written recursion:       5,848,602,848 bytes allocated in the heap

If you make any change here, pay close attention to the T9872{a,b,c} tests
and T5321Fun.

If we need to make this yet more performant, a possible way forward is to
duplicate the flattener code for the nominal case, and make that case
faster. This doesn't seem quite worth it, yet.

Note [flatten_exact_fam_app_fully performance]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The refactor of GRefl seems to cause performance trouble for T9872x:
the allocation of flatten_exact_fam_app_fully_performance
increased. See note [Generalized reflexive coercion] in
GHC.Core.TyCo.Rep for more information about GRefl and #15192 for the
current state.

The explicit pattern match in homogenise_result helps with T9872a, b, c.

Still, it increases the expected allocation of T9872d by ~2%.

TODO: a step-by-step replay of the refactor to analyze the performance.

-}</span><span>
</span><span id="line-970"></span><span>
</span><span id="line-971"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-pragma hs-type">flatten_args_tc</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-972"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-identifier hs-type">flatten_args_tc</span></a></span><span>
</span><span id="line-973"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>         </span><span class="hs-comment">-- T</span><span>
</span><span id="line-974"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span>        </span><span class="hs-comment">-- Role r</span><span>
</span><span id="line-975"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>        </span><span class="hs-comment">-- Arg types [t1,..,tn]</span><span>
</span><span id="line-976"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- List of flattened args [x1,..,xn]</span><span>
</span><span id="line-977"></span><span>                   </span><span class="hs-comment">-- 1-1 corresp with [t1,..,tn]</span><span>
</span><span id="line-978"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- List of arg coercions [co1,..,con]</span><span>
</span><span id="line-979"></span><span>                         </span><span class="hs-comment">-- 1-1 corresp with [t1,..,tn]</span><span>
</span><span id="line-980"></span><span>                         </span><span class="hs-comment">--    coi :: xi ~r ti</span><span>
</span><span id="line-981"></span><span>           </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- Result coercion, rco</span><span>
</span><span id="line-982"></span><span>                         </span><span class="hs-comment">--    rco : (T t1..tn) ~N (T (x1 |&gt; co1) .. (xn |&gt; con))</span><span>
</span><span id="line-983"></span><span id="flatten_args_tc"><span class="annot"><span class="annottext">flatten_args_tc :: TyCon
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-identifier hs-var hs-var">flatten_args_tc</span></a></span></span><span> </span><span id="local-6989586621681115167"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115167"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; Bool
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-identifier hs-var">flatten_args</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115165"><span class="hs-identifier hs-var">all_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115164"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115163"><span class="hs-identifier hs-var">inner_ki</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="GHC.Types.Var.Set.html#emptyVarSet"><span class="hs-identifier hs-var">emptyVarSet</span></a></span><span>
</span><span id="line-984"></span><span>  </span><span class="hs-comment">-- NB: TyCon kinds are always closed</span><span>
</span><span id="line-985"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-986"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621681115161"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115161"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115160"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115160"><span class="hs-identifier hs-var">named</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-987"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyConBinder] -&gt; ([TyCoBinder], Bool)
</span><a href="GHC.Tc.Solver.Flatten.html#ty_con_binders_ty_binders%27"><span class="hs-identifier hs-var">ty_con_binders_ty_binders'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [TyConBinder]
</span><a href="GHC.Core.TyCon.html#tyConBinders"><span class="hs-identifier hs-var hs-var">tyConBinders</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115167"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-988"></span><span>    </span><span class="hs-comment">-- it's possible that the result kind has arrows (for, e.g., a type family)</span><span>
</span><span id="line-989"></span><span>    </span><span class="hs-comment">-- so we must split it</span><span>
</span><span id="line-990"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621681115157"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115157"><span class="hs-identifier hs-var">inner_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115163"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115163"><span class="hs-identifier hs-var">inner_ki</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115156"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115156"><span class="hs-identifier hs-var">inner_named</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="GHC.Tc.Solver.Flatten.html#split_pi_tys%27"><span class="hs-identifier hs-var">split_pi_tys'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; TcType
</span><a href="GHC.Core.TyCon.html#tyConResKind"><span class="hs-identifier hs-var hs-var">tyConResKind</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115167"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-991"></span><span>    </span><span class="hs-glyph">!</span><span id="local-6989586621681115165"><span class="annot"><span class="annottext">all_bndrs :: [TyCoBinder]
</span><a href="#local-6989586621681115165"><span class="hs-identifier hs-var hs-var">all_bndrs</span></a></span></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115161"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder] -&gt; [TyCoBinder] -&gt; [TyCoBinder]
forall {a}. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#chkAppend"><span class="hs-operator hs-var">`chkAppend`</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115157"><span class="hs-identifier hs-var">inner_bndrs</span></a></span><span>
</span><span id="line-992"></span><span>    </span><span class="hs-glyph">!</span><span id="local-6989586621681115164"><span class="annot"><span class="annottext">any_named_bndrs :: Bool
</span><a href="#local-6989586621681115164"><span class="hs-identifier hs-var hs-var">any_named_bndrs</span></a></span></span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115160"><span class="hs-identifier hs-var">named</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115156"><span class="hs-identifier hs-var">inner_named</span></a></span><span>
</span><span id="line-993"></span><span>    </span><span class="hs-comment">-- NB: Those bangs there drop allocations in T9872{a,c,d} by 8%.</span><span>
</span><span id="line-994"></span><span>
</span><span id="line-995"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-pragma hs-type">flatten_args</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-996"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-identifier hs-type">flatten_args</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-comment">-- Binders, and True iff any of them are</span><span>
</span><span id="line-997"></span><span>                                     </span><span class="hs-comment">-- named.</span><span>
</span><span id="line-998"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcTyCoVarSet"><span class="hs-identifier hs-type">TcTyCoVarSet</span></a></span><span> </span><span class="hs-comment">-- function kind; kind's free vars</span><span>
</span><span id="line-999"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>     </span><span class="hs-comment">-- these are in 1-to-1 correspondence</span><span>
</span><span id="line-1000"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1001"></span><span class="hs-comment">-- Coercions :: Xi ~ Type, at roles given</span><span>
</span><span id="line-1002"></span><span class="hs-comment">-- Third coercion :: tcTypeKind(fun xis) ~N tcTypeKind(fun tys)</span><span>
</span><span id="line-1003"></span><span class="hs-comment">-- That is, the third coercion relates the kind of some function (whose kind is</span><span>
</span><span id="line-1004"></span><span class="hs-comment">-- passed as the first parameter) instantiated at xis to the kind of that</span><span>
</span><span id="line-1005"></span><span class="hs-comment">-- function instantiated at the tys. This is useful in keeping flattening</span><span>
</span><span id="line-1006"></span><span class="hs-comment">-- homoegeneous. The list of roles must be at least as long as the list of</span><span>
</span><span id="line-1007"></span><span class="hs-comment">-- types.</span><span>
</span><span id="line-1008"></span><span id="flatten_args"><span class="annot"><span class="annottext">flatten_args :: [TyCoBinder]
-&gt; Bool
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-identifier hs-var hs-var">flatten_args</span></a></span></span><span> </span><span id="local-6989586621681115150"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115150"><span class="hs-identifier hs-var">orig_binders</span></a></span></span><span>
</span><span id="line-1009"></span><span>             </span><span id="local-6989586621681115149"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115149"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span></span><span>
</span><span id="line-1010"></span><span>             </span><span id="local-6989586621681115148"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115148"><span class="hs-identifier hs-var">orig_inner_ki</span></a></span></span><span>
</span><span id="line-1011"></span><span>             </span><span id="local-6989586621681115147"><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681115147"><span class="hs-identifier hs-var">orig_fvs</span></a></span></span><span>
</span><span id="line-1012"></span><span>             </span><span id="local-6989586621681115146"><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115146"><span class="hs-identifier hs-var">orig_roles</span></a></span></span><span>
</span><span id="line-1013"></span><span>             </span><span id="local-6989586621681115145"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115145"><span class="hs-identifier hs-var">orig_tys</span></a></span></span><span>
</span><span id="line-1014"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681115149"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span><span>
</span><span id="line-1015"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_slow"><span class="hs-identifier hs-var">flatten_args_slow</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115150"><span class="hs-identifier hs-var">orig_binders</span></a></span><span>
</span><span id="line-1016"></span><span>                           </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115148"><span class="hs-identifier hs-var">orig_inner_ki</span></a></span><span>
</span><span id="line-1017"></span><span>                           </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681115147"><span class="hs-identifier hs-var">orig_fvs</span></a></span><span>
</span><span id="line-1018"></span><span>                           </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115146"><span class="hs-identifier hs-var">orig_roles</span></a></span><span>
</span><span id="line-1019"></span><span>                           </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115145"><span class="hs-identifier hs-var">orig_tys</span></a></span><span>
</span><span id="line-1020"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; TcType
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_fast"><span class="hs-identifier hs-var">flatten_args_fast</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115150"><span class="hs-identifier hs-var">orig_binders</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115148"><span class="hs-identifier hs-var">orig_inner_ki</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115146"><span class="hs-identifier hs-var">orig_roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115145"><span class="hs-identifier hs-var">orig_tys</span></a></span><span>
</span><span id="line-1021"></span><span>
</span><span id="line-1022"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_fast"><span class="hs-pragma hs-type">flatten_args_fast</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1023"></span><span class="hs-comment">-- | fast path flatten_args, in which none of the binders are named and</span><span>
</span><span id="line-1024"></span><span class="hs-comment">-- therefore we can avoid tracking a lifting context.</span><span>
</span><span id="line-1025"></span><span class="hs-comment">-- There are many bang patterns in here. It's been observed that they</span><span>
</span><span id="line-1026"></span><span class="hs-comment">-- greatly improve performance of an optimized build.</span><span>
</span><span id="line-1027"></span><span class="hs-comment">-- The T9872 test cases are good witnesses of this fact.</span><span>
</span><span id="line-1028"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_fast"><span class="hs-identifier hs-type">flatten_args_fast</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1029"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span>
</span><span id="line-1030"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1031"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1032"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1033"></span><span id="flatten_args_fast"><span class="annot"><span class="annottext">flatten_args_fast :: [TyCoBinder]
-&gt; TcType
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_fast"><span class="hs-identifier hs-var hs-var">flatten_args_fast</span></a></span></span><span> </span><span id="local-6989586621681115142"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115142"><span class="hs-identifier hs-var">orig_binders</span></a></span></span><span> </span><span id="local-6989586621681115141"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115141"><span class="hs-identifier hs-var">orig_inner_ki</span></a></span></span><span> </span><span id="local-6989586621681115140"><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115140"><span class="hs-identifier hs-var">orig_roles</span></a></span></span><span> </span><span id="local-6989586621681115139"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115139"><span class="hs-identifier hs-var">orig_tys</span></a></span></span><span>
</span><span id="line-1034"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(([TcType], [CoercionN], [TyCoBinder])
 -&gt; ([TcType], [CoercionN], CoercionN))
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">([TcType], [CoercionN], [TyCoBinder])
-&gt; ([TcType], [CoercionN], CoercionN)
</span><a href="#local-6989586621681115138"><span class="hs-identifier hs-var">finish</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcType]
-&gt; [Role]
-&gt; [TyCoBinder]
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
</span><a href="#local-6989586621681115137"><span class="hs-identifier hs-var">iterate</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115139"><span class="hs-identifier hs-var">orig_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115140"><span class="hs-identifier hs-var">orig_roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115142"><span class="hs-identifier hs-var">orig_binders</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1035"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1036"></span><span>
</span><span id="line-1037"></span><span>    </span><span class="annot"><a href="#local-6989586621681115137"><span class="hs-identifier hs-type">iterate</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1038"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1039"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1040"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1041"></span><span>    </span><span id="local-6989586621681115137"><span class="annot"><span class="annottext">iterate :: [TcType]
-&gt; [Role]
-&gt; [TyCoBinder]
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
</span><a href="#local-6989586621681115137"><span class="hs-identifier hs-var hs-var">iterate</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115136"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115136"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621681115135"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115135"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115134"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115134"><span class="hs-keyword hs-var">role</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621681115133"><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115133"><span class="hs-identifier hs-var">roles</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCoBinder
</span><span class="hs-identifier">_</span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621681115132"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115132"><span class="hs-identifier hs-var">binders</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1042"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621681115131"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115131"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115130"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115130"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115129"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115134"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115136"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1043"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621681115128"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115128"><span class="hs-identifier hs-var">xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115127"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115127"><span class="hs-identifier hs-var">cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115126"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115126"><span class="hs-identifier hs-var">binders</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TcType]
-&gt; [Role]
-&gt; [TyCoBinder]
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
</span><a href="#local-6989586621681115137"><span class="hs-identifier hs-var">iterate</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115135"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115133"><span class="hs-identifier hs-var">roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115132"><span class="hs-identifier hs-var">binders</span></a></span><span>
</span><span id="line-1044"></span><span>      </span><span class="annot"><span class="annottext">([TcType], [CoercionN], [TyCoBinder])
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115131"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; [TcType]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115128"><span class="hs-identifier hs-var">xis</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115130"><span class="hs-identifier hs-var">co</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; [CoercionN] -&gt; [CoercionN]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115127"><span class="hs-identifier hs-var">cos</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115126"><span class="hs-identifier hs-var">binders</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1045"></span><span>    </span><span class="annot"><a href="#local-6989586621681115137"><span class="hs-identifier hs-var">iterate</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[Role]
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681115125"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115125"><span class="hs-identifier hs-var">binders</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([TcType], [CoercionN], [TyCoBinder])
-&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115125"><span class="hs-identifier hs-var">binders</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1046"></span><span>    </span><span class="annot"><a href="#local-6989586621681115137"><span class="hs-identifier hs-var">iterate</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ([TcType], [CoercionN], [TyCoBinder])
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span>
</span><span id="line-1047"></span><span>        </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten_args wandered into deeper water than usual&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1048"></span><span>           </span><span class="hs-comment">-- This debug information is commented out because leaving it in</span><span>
</span><span id="line-1049"></span><span>           </span><span class="hs-comment">-- causes a ~2% increase in allocations in T9872{a,c,d}.</span><span>
</span><span id="line-1050"></span><span>           </span><span class="hs-comment">{-
             (vcat [ppr orig_binders,
                    ppr orig_inner_ki,
                    ppr (take 10 orig_roles), -- often infinite!
                    ppr orig_tys])
           -}</span><span>
</span><span id="line-1056"></span><span>
</span><span id="line-1057"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621681115129"><span class="hs-pragma hs-type">go</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1058"></span><span>    </span><span class="annot"><a href="#local-6989586621681115129"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span>
</span><span id="line-1059"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>
</span><span id="line-1060"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1061"></span><span>    </span><span id="local-6989586621681115129"><span class="annot"><span class="annottext">go :: Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115129"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621681115124"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115124"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span id="local-6989586621681115123"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115123"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-1062"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115124"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1063"></span><span>          </span><span class="hs-comment">-- In the slow path we bind the Xi and Coercion from the recursive</span><span>
</span><span id="line-1064"></span><span>          </span><span class="hs-comment">-- call and then use it such</span><span>
</span><span id="line-1065"></span><span>          </span><span class="hs-comment">--</span><span>
</span><span id="line-1066"></span><span>          </span><span class="hs-comment">--   let kind_co = mkTcSymCo $ mkReflCo Nominal (tyBinderType binder)</span><span>
</span><span id="line-1067"></span><span>          </span><span class="hs-comment">--       casted_xi = xi `mkCastTy` kind_co</span><span>
</span><span id="line-1068"></span><span>          </span><span class="hs-comment">--       casted_co = xi |&gt; kind_co ~r xi ; co</span><span>
</span><span id="line-1069"></span><span>          </span><span class="hs-comment">--</span><span>
</span><span id="line-1070"></span><span>          </span><span class="hs-comment">-- but this isn't necessary:</span><span>
</span><span id="line-1071"></span><span>          </span><span class="hs-comment">--   mkTcSymCo (Refl a b) = Refl a b,</span><span>
</span><span id="line-1072"></span><span>          </span><span class="hs-comment">--   mkCastTy x (Refl _ _) = x</span><span>
</span><span id="line-1073"></span><span>          </span><span class="hs-comment">--   mkTcGReflLeftCo _ ty (Refl _ _) `mkTransCo` co = co</span><span>
</span><span id="line-1074"></span><span>          </span><span class="hs-comment">--</span><span>
</span><span id="line-1075"></span><span>          </span><span class="hs-comment">-- Also, no need to check isAnonTyCoBinder or isNamedBinder, since</span><span>
</span><span id="line-1076"></span><span>          </span><span class="hs-comment">-- we've already established that they're all anonymous.</span><span>
</span><span id="line-1077"></span><span>          </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span>  </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115123"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1078"></span><span>          </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Representational"><span class="hs-identifier hs-var">Representational</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115123"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1079"></span><span>          </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Phantom"><span class="hs-identifier hs-var">Phantom</span></a></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-comment">-- See Note [Phantoms in the flattener]</span><span>
</span><span id="line-1080"></span><span>                              </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115119"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115119"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS TcType -&gt; FlatM TcType
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS TcType -&gt; FlatM TcType) -&gt; TcS TcType -&gt; FlatM TcType
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115123"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1081"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115119"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkReflCo"><span class="hs-identifier hs-var">mkReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Phantom"><span class="hs-identifier hs-var">Phantom</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115119"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1082"></span><span>
</span><span id="line-1083"></span><span>
</span><span id="line-1084"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621681115138"><span class="hs-pragma hs-type">finish</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1085"></span><span>    </span><span class="annot"><a href="#local-6989586621681115138"><span class="hs-identifier hs-type">finish</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1086"></span><span>    </span><span id="local-6989586621681115138"><span class="annot"><span class="annottext">finish :: ([TcType], [CoercionN], [TyCoBinder])
-&gt; ([TcType], [CoercionN], CoercionN)
</span><a href="#local-6989586621681115138"><span class="hs-identifier hs-var hs-var">finish</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115116"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115116"><span class="hs-identifier hs-var">xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115115"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115115"><span class="hs-identifier hs-var">cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115114"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115114"><span class="hs-identifier hs-var">binders</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115116"><span class="hs-identifier hs-var">xis</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681115115"><span class="hs-identifier hs-var">cos</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115113"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1087"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1088"></span><span>        </span><span id="local-6989586621681115112"><span class="annot"><span class="annottext">final_kind :: TcType
</span><a href="#local-6989586621681115112"><span class="hs-identifier hs-var hs-var">final_kind</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder] -&gt; TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkPiTys"><span class="hs-identifier hs-var">mkPiTys</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115114"><span class="hs-identifier hs-var">binders</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115141"><span class="hs-identifier hs-var">orig_inner_ki</span></a></span><span>
</span><span id="line-1089"></span><span>        </span><span id="local-6989586621681115113"><span class="annot"><span class="annottext">kind_co :: CoercionN
</span><a href="#local-6989586621681115113"><span class="hs-identifier hs-var hs-var">kind_co</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkNomReflCo"><span class="hs-identifier hs-var">mkNomReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115112"><span class="hs-identifier hs-var">final_kind</span></a></span><span>
</span><span id="line-1090"></span><span>
</span><span id="line-1091"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_slow"><span class="hs-pragma hs-type">flatten_args_slow</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1092"></span><span class="hs-comment">-- | Slow path, compared to flatten_args_fast, because this one must track</span><span>
</span><span id="line-1093"></span><span class="hs-comment">-- a lifting context.</span><span>
</span><span id="line-1094"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_args_slow"><span class="hs-identifier hs-type">flatten_args_slow</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcTyCoVarSet"><span class="hs-identifier hs-type">TcTyCoVarSet</span></a></span><span>
</span><span id="line-1095"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1096"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1097"></span><span id="flatten_args_slow"><span class="annot"><span class="annottext">flatten_args_slow :: [TyCoBinder]
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_slow"><span class="hs-identifier hs-var hs-var">flatten_args_slow</span></a></span></span><span> </span><span id="local-6989586621681115109"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115109"><span class="hs-identifier hs-var">binders</span></a></span></span><span> </span><span id="local-6989586621681115108"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115108"><span class="hs-identifier hs-var">inner_ki</span></a></span></span><span> </span><span id="local-6989586621681115107"><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681115107"><span class="hs-identifier hs-var">fvs</span></a></span></span><span> </span><span id="local-6989586621681115106"><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115106"><span class="hs-identifier hs-var">roles</span></a></span></span><span> </span><span id="local-6989586621681115105"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115105"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-1098"></span><span class="hs-comment">-- Arguments used dependently must be flattened with proper coercions, but</span><span>
</span><span id="line-1099"></span><span class="hs-comment">-- we're not guaranteed to get a proper coercion when flattening with the</span><span>
</span><span id="line-1100"></span><span class="hs-comment">-- &quot;Derived&quot; flavour. So we must call noBogusCoercions when flattening arguments</span><span>
</span><span id="line-1101"></span><span class="hs-comment">-- corresponding to binders that are dependent. However, we might legitimately</span><span>
</span><span id="line-1102"></span><span class="hs-comment">-- have *more* arguments than binders, in the case that the inner_ki is a variable</span><span>
</span><span id="line-1103"></span><span class="hs-comment">-- that gets instantiated with a &#928;-type. We conservatively choose not to produce</span><span>
</span><span id="line-1104"></span><span class="hs-comment">-- bogus coercions for these, too. Note that this might miss an opportunity for</span><span>
</span><span id="line-1105"></span><span class="hs-comment">-- a Derived rewriting a Derived. The solution would be to generate evidence for</span><span>
</span><span id="line-1106"></span><span class="hs-comment">-- Deriveds, thus avoiding this whole noBogusCoercions idea. See also</span><span>
</span><span id="line-1107"></span><span class="hs-comment">-- Note [No derived kind equalities]</span><span>
</span><span id="line-1108"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115104"><span class="annot"><span class="annottext">[(TcType, CoercionN)]
</span><a href="#local-6989586621681115104"><span class="hs-identifier hs-var">flattened_args</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Bool -&gt; Role -&gt; TcType -&gt; FlatM (TcType, CoercionN))
-&gt; [Bool] -&gt; [Role] -&gt; [TcType] -&gt; FlatM [(TcType, CoercionN)]
forall (m :: * -&gt; *) a b c d.
Monad m =&gt;
(a -&gt; b -&gt; c -&gt; m d) -&gt; [a] -&gt; [b] -&gt; [c] -&gt; m [d]
</span><a href="GHC.Utils.Monad.html#zipWith3M"><span class="hs-identifier hs-var">zipWith3M</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115103"><span class="hs-identifier hs-var">fl</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TyCoBinder -&gt; Bool) -&gt; [TyCoBinder] -&gt; [Bool]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TyCoBinder -&gt; Bool
</span><a href="GHC.Core.TyCo.Rep.html#isNamedBinder"><span class="hs-identifier hs-var">isNamedBinder</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115109"><span class="hs-identifier hs-var">binders</span></a></span><span> </span><span class="annot"><span class="annottext">[Bool] -&gt; [Bool] -&gt; [Bool]
forall {a}. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; [Bool]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span>
</span><span id="line-1109"></span><span>                                        </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115106"><span class="hs-identifier hs-var">roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115105"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1110"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcType], [CoercionN], CoercionN)
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [(TcType, CoercionN)]
-&gt; ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Core.Coercion.html#simplifyArgsWorker"><span class="hs-identifier hs-var">simplifyArgsWorker</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681115109"><span class="hs-identifier hs-var">binders</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115108"><span class="hs-identifier hs-var">inner_ki</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681115107"><span class="hs-identifier hs-var">fvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681115106"><span class="hs-identifier hs-var">roles</span></a></span><span> </span><span class="annot"><span class="annottext">[(TcType, CoercionN)]
</span><a href="#local-6989586621681115104"><span class="hs-identifier hs-var">flattened_args</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1111"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1112"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621681115103"><span class="hs-pragma hs-type">fl</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1113"></span><span>    </span><span class="annot"><a href="#local-6989586621681115103"><span class="hs-identifier hs-type">fl</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- must we ensure to produce a real coercion here?</span><span>
</span><span id="line-1114"></span><span>                  </span><span class="hs-comment">-- see comment at top of function</span><span>
</span><span id="line-1115"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1116"></span><span>    </span><span id="local-6989586621681115103"><span class="annot"><span class="annottext">fl :: Bool -&gt; Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115103"><span class="hs-identifier hs-var hs-var">fl</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>  </span><span id="local-6989586621681115100"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115100"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span id="local-6989586621681115099"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115099"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#noBogusCoercions"><span class="hs-identifier hs-var">noBogusCoercions</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115098"><span class="hs-identifier hs-var">fl1</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115100"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115099"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1117"></span><span>    </span><span class="annot"><a href="#local-6989586621681115103"><span class="hs-identifier hs-var">fl</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span id="local-6989586621681115097"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115097"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span id="local-6989586621681115096"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115096"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>                    </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115098"><span class="hs-identifier hs-var">fl1</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115097"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115096"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1118"></span><span>
</span><span id="line-1119"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621681115098"><span class="hs-pragma hs-type">fl1</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1120"></span><span>    </span><span class="annot"><a href="#local-6989586621681115098"><span class="hs-identifier hs-type">fl1</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1121"></span><span>    </span><span id="local-6989586621681115098"><span class="annot"><span class="annottext">fl1 :: Role -&gt; TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="#local-6989586621681115098"><span class="hs-identifier hs-var hs-var">fl1</span></a></span></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span> </span><span id="local-6989586621681115095"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115095"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-1122"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1123"></span><span>        </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115095"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1124"></span><span>
</span><span id="line-1125"></span><span>    </span><span class="annot"><a href="#local-6989586621681115098"><span class="hs-identifier hs-var">fl1</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Representational"><span class="hs-identifier hs-var">Representational</span></a></span><span> </span><span id="local-6989586621681115094"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115094"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-1126"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1127"></span><span>        </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115094"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1128"></span><span>
</span><span id="line-1129"></span><span>    </span><span class="annot"><a href="#local-6989586621681115098"><span class="hs-identifier hs-var">fl1</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Phantom"><span class="hs-identifier hs-var">Phantom</span></a></span><span> </span><span id="local-6989586621681115093"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115093"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-1130"></span><span>    </span><span class="hs-comment">-- See Note [Phantoms in the flattener]</span><span>
</span><span id="line-1131"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115092"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115092"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS TcType -&gt; FlatM TcType
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS TcType -&gt; FlatM TcType) -&gt; TcS TcType -&gt; FlatM TcType
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115093"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1132"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115092"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkReflCo"><span class="hs-identifier hs-var">mkReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Phantom"><span class="hs-identifier hs-var">Phantom</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115092"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1133"></span><span>
</span><span id="line-1134"></span><span class="hs-comment">------------------</span><span>
</span><span id="line-1135"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-type">flatten_one</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1136"></span><span class="hs-comment">-- Flatten a type to get rid of type function applications, returning</span><span>
</span><span id="line-1137"></span><span class="hs-comment">-- the new type-function-free type, and a collection of new equality</span><span>
</span><span id="line-1138"></span><span class="hs-comment">-- constraints.  See Note [Flattening] for more detail.</span><span>
</span><span id="line-1139"></span><span class="hs-comment">--</span><span>
</span><span id="line-1140"></span><span class="hs-comment">-- Postcondition: Coercion :: Xi ~ TcType</span><span>
</span><span id="line-1141"></span><span class="hs-comment">-- The role on the result coercion matches the EqRel in the FlattenEnv</span><span>
</span><span id="line-1142"></span><span>
</span><span id="line-1143"></span><span id="flatten_one"><span class="annot"><span class="annottext">flatten_one :: TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var hs-var">flatten_one</span></a></span></span><span> </span><span id="local-6989586621681115091"><span class="annot"><span class="annottext">xi :: TcType
</span><a href="#local-6989586621681115091"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#LitTy"><span class="hs-identifier hs-type">LitTy</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1144"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115089"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115089"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1145"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115091"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkReflCo"><span class="hs-identifier hs-var">mkReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115089"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115091"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1146"></span><span>
</span><span id="line-1147"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyVarTy"><span class="hs-identifier hs-type">TyVarTy</span></a></span><span> </span><span id="local-6989586621681115087"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115087"><span class="hs-identifier hs-var">tv</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1148"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flattenTyVar"><span class="hs-identifier hs-var">flattenTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681115087"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1149"></span><span>
</span><span id="line-1150"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#AppTy"><span class="hs-identifier hs-type">AppTy</span></a></span><span> </span><span id="local-6989586621681115085"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115085"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span id="local-6989586621681115084"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115084"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1151"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_tys"><span class="hs-identifier hs-var">flatten_app_tys</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115085"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115084"><span class="hs-identifier hs-var">ty2</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1152"></span><span>
</span><span id="line-1153"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyConApp"><span class="hs-identifier hs-type">TyConApp</span></a></span><span> </span><span id="local-6989586621681115081"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681115080"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115080"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1154"></span><span>  </span><span class="hs-comment">-- Expand type synonyms that mention type families</span><span>
</span><span id="line-1155"></span><span>  </span><span class="hs-comment">-- on the RHS; see Note [Flattening synonyms]</span><span>
</span><span id="line-1156"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115079"><span class="annot"><span class="annottext">[(TcTyVar, TcType)]
</span><a href="#local-6989586621681115079"><span class="hs-identifier hs-var">tenv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115078"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115078"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115077"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115077"><span class="hs-identifier hs-var">tys'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; Maybe ([(TcTyVar, TcType)], TcType, [TcType])
forall tyco.
TyCon -&gt; [tyco] -&gt; Maybe ([(TcTyVar, tyco)], TcType, [tyco])
</span><a href="GHC.Core.TyCon.html#expandSynTyCon_maybe"><span class="hs-identifier hs-var">expandSynTyCon_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115080"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1157"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681115073"><span class="annot"><span class="annottext">expanded_ty :: TcType
</span><a href="#local-6989586621681115073"><span class="hs-identifier hs-var hs-var">expanded_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.Type.html#mkAppTys"><span class="hs-identifier hs-var">mkAppTys</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasCallStack =&gt; TCvSubst -&gt; TcType -&gt; TcType
TCvSubst -&gt; TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier hs-var">substTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(TcTyVar, TcType)] -&gt; TCvSubst
</span><a href="GHC.Core.TyCo.Subst.html#mkTvSubstPrs"><span class="hs-identifier hs-var">mkTvSubstPrs</span></a></span><span> </span><span class="annot"><span class="annottext">[(TcTyVar, TcType)]
</span><a href="#local-6989586621681115079"><span class="hs-identifier hs-var">tenv</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115078"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115077"><span class="hs-identifier hs-var">tys'</span></a></span><span>
</span><span id="line-1158"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115069"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115069"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span>
</span><span id="line-1159"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681115069"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1160"></span><span>           </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isFamFreeTyCon"><span class="hs-identifier hs-var">isFamFreeTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1161"></span><span>                         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115073"><span class="hs-identifier hs-var">expanded_ty</span></a></span><span>
</span><span id="line-1162"></span><span>           </span><span class="annot"><span class="annottext">FlattenMode
</span><span class="hs-identifier">_</span></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_ty_con_app"><span class="hs-identifier hs-var">flatten_ty_con_app</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115080"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1163"></span><span>
</span><span id="line-1164"></span><span>  </span><span class="hs-comment">-- Otherwise, it's a type function application, and we have to</span><span>
</span><span id="line-1165"></span><span>  </span><span class="hs-comment">-- flatten it away as well, and generate a new given equality constraint</span><span>
</span><span id="line-1166"></span><span>  </span><span class="hs-comment">-- between the application and a newly generated flattening skolem variable.</span><span>
</span><span id="line-1167"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier hs-var">isTypeFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1168"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_fam_app"><span class="hs-identifier hs-var">flatten_fam_app</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115080"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1169"></span><span>
</span><span id="line-1170"></span><span>  </span><span class="hs-comment">-- For * a normal data type application</span><span>
</span><span id="line-1171"></span><span>  </span><span class="hs-comment">--     * data family application</span><span>
</span><span id="line-1172"></span><span>  </span><span class="hs-comment">-- we just recursively flatten the arguments.</span><span>
</span><span id="line-1173"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1174"></span><span class="hs-comment">-- FM_Avoid stuff commented out; see Note [Lazy flattening]</span><span>
</span><span id="line-1175"></span><span class="hs-comment">--  , let fmode' = case fmode of  -- Switch off the flat_top bit in FM_Avoid</span><span>
</span><span id="line-1176"></span><span class="hs-comment">--                   FE { fe_mode = FM_Avoid tv _ }</span><span>
</span><span id="line-1177"></span><span class="hs-comment">--                     -&gt; fmode { fe_mode = FM_Avoid tv False }</span><span>
</span><span id="line-1178"></span><span class="hs-comment">--                   _ -&gt; fmode</span><span>
</span><span id="line-1179"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_ty_con_app"><span class="hs-identifier hs-var">flatten_ty_con_app</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115081"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115080"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1180"></span><span>
</span><span id="line-1181"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span id="local-6989586621681115063"><span class="annot"><span class="annottext">ty :: TcType
</span><a href="#local-6989586621681115063"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#FunTy"><span class="hs-identifier hs-type">FunTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ft_mult :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_mult"><span class="hs-identifier hs-var">ft_mult</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681115060"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115060"><span class="hs-identifier hs-var">mult</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_arg :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_arg"><span class="hs-identifier hs-var">ft_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681115058"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115058"><span class="hs-identifier hs-var">ty1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_res :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_res"><span class="hs-identifier hs-var">ft_res</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681115056"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115056"><span class="hs-identifier hs-var">ty2</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1182"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115055"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115055"><span class="hs-identifier hs-var">xi1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621681115054"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115054"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115058"><span class="hs-identifier hs-var">ty1</span></a></span><span>
</span><span id="line-1183"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115053"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115053"><span class="hs-identifier hs-var">xi2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621681115052"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115052"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115056"><span class="hs-identifier hs-var">ty2</span></a></span><span>
</span><span id="line-1184"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115051"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115051"><span class="hs-identifier hs-var">xi3</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621681115050"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115050"><span class="hs-identifier hs-var">co3</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115060"><span class="hs-identifier hs-var">mult</span></a></span><span>
</span><span id="line-1185"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115049"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115049"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1186"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115063"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ft_mult :: TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_mult"><span class="hs-identifier hs-var">ft_mult</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115051"><span class="hs-identifier hs-var">xi3</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_arg :: TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_arg"><span class="hs-identifier hs-var">ft_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115055"><span class="hs-identifier hs-var">xi1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_res :: TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_res"><span class="hs-identifier hs-var">ft_res</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115053"><span class="hs-identifier hs-var">xi2</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1187"></span><span>                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Role -&gt; CoercionN -&gt; CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkFunCo"><span class="hs-identifier hs-var">mkFunCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115049"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115050"><span class="hs-identifier hs-var">co3</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115054"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115052"><span class="hs-identifier hs-var">co2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1188"></span><span>
</span><span id="line-1189"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span id="local-6989586621681115047"><span class="annot"><span class="annottext">ty :: TcType
</span><a href="#local-6989586621681115047"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ForAllTy"><span class="hs-identifier hs-type">ForAllTy</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1190"></span><span class="hs-comment">-- TODO (RAE): This is inadequate, as it doesn't flatten the kind of</span><span>
</span><span id="line-1191"></span><span class="hs-comment">-- the bound tyvar. Doing so will require carrying around a substitution</span><span>
</span><span id="line-1192"></span><span class="hs-comment">-- and the usual substTyVarBndr-like silliness. Argh.</span><span>
</span><span id="line-1193"></span><span>
</span><span id="line-1194"></span><span class="hs-comment">-- We allow for-alls when, but only when, no type function</span><span>
</span><span id="line-1195"></span><span class="hs-comment">-- applications inside the forall involve the bound type variables.</span><span>
</span><span id="line-1196"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115045"><span class="annot"><span class="annottext">[TyVarBinder]
</span><a href="#local-6989586621681115045"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115044"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115044"><span class="hs-identifier hs-var">rho</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; ([TyVarBinder], TcType)
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitForAllVarBndrs"><span class="hs-identifier hs-var">tcSplitForAllVarBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115047"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1197"></span><span>             </span><span id="local-6989586621681115042"><span class="annot"><span class="annottext">tvs :: [TcTyVar]
</span><a href="#local-6989586621681115042"><span class="hs-identifier hs-var hs-var">tvs</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVarBinder] -&gt; [TcTyVar]
forall tv argf. [VarBndr tv argf] -&gt; [tv]
</span><a href="GHC.Types.Var.html#binderVars"><span class="hs-identifier hs-var">binderVars</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVarBinder]
</span><a href="#local-6989586621681115045"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-1198"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115040"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115040"><span class="hs-identifier hs-var">rho'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115039"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115039"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlattenMode
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. FlattenMode -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setMode"><span class="hs-identifier hs-var">setMode</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115044"><span class="hs-identifier hs-var">rho</span></a></span><span>
</span><span id="line-1199"></span><span>                         </span><span class="hs-comment">-- Substitute only under a forall</span><span>
</span><span id="line-1200"></span><span>                         </span><span class="hs-comment">-- See Note [Flattening under a forall]</span><span>
</span><span id="line-1201"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVarBinder] -&gt; TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkForAllTys"><span class="hs-identifier hs-var">mkForAllTys</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVarBinder]
</span><a href="#local-6989586621681115045"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115040"><span class="hs-identifier hs-var">rho'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkHomoForAllCos"><span class="hs-identifier hs-var">mkHomoForAllCos</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681115042"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115039"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1202"></span><span>
</span><span id="line-1203"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CastTy"><span class="hs-identifier hs-type">CastTy</span></a></span><span> </span><span id="local-6989586621681115035"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115035"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span id="local-6989586621681115034"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115034"><span class="hs-identifier hs-var">g</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1204"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115033"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115033"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115032"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115032"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115035"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1205"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115031"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115031"><span class="hs-identifier hs-var">g'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; FlatM (CoercionN, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_co"><span class="hs-identifier hs-var">flatten_co</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115034"><span class="hs-identifier hs-var">g</span></a></span><span>
</span><span id="line-1206"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115029"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115029"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1207"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-identifier hs-var">mkCastTy</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115033"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115031"><span class="hs-identifier hs-var">g'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; Role -&gt; TcType -&gt; TcType -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#castCoercionKind1"><span class="hs-identifier hs-var">castCoercionKind1</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115032"><span class="hs-identifier hs-var">co</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115029"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115033"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115035"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115031"><span class="hs-identifier hs-var">g'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1208"></span><span>         </span><span class="hs-comment">-- It makes a /big/ difference to call castCoercionKind1 not</span><span>
</span><span id="line-1209"></span><span>         </span><span class="hs-comment">-- the more general castCoercionKind2.</span><span>
</span><span id="line-1210"></span><span>         </span><span class="hs-comment">-- See Note [castCoercionKind1] in GHC.Core.Coercion</span><span>
</span><span id="line-1211"></span><span>
</span><span id="line-1212"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionTy"><span class="hs-identifier hs-type">CoercionTy</span></a></span><span> </span><span id="local-6989586621681115025"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115025"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoercionN -&gt; TcType)
-&gt; (CoercionN, CoercionN) -&gt; (TcType, CoercionN)
forall (a :: * -&gt; * -&gt; *) b c d.
Arrow a =&gt;
a b c -&gt; a (b, d) (c, d)
</span><a href="../../base/src/Control.Arrow.html#first"><span class="hs-identifier hs-var">first</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCoercionTy"><span class="hs-identifier hs-var">mkCoercionTy</span></a></span><span> </span><span class="annot"><span class="annottext">((CoercionN, CoercionN) -&gt; (TcType, CoercionN))
-&gt; FlatM (CoercionN, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; FlatM (CoercionN, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_co"><span class="hs-identifier hs-var">flatten_co</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115025"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-1213"></span><span>
</span><span id="line-1214"></span><span class="hs-comment">-- | &quot;Flatten&quot; a coercion. Really, just zonk it so we can uphold</span><span>
</span><span id="line-1215"></span><span class="hs-comment">-- (F1) of Note [Flattening]</span><span>
</span><span id="line-1216"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_co"><span class="hs-identifier hs-type">flatten_co</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1217"></span><span id="flatten_co"><span class="annot"><span class="annottext">flatten_co :: CoercionN -&gt; FlatM (CoercionN, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_co"><span class="hs-identifier hs-var hs-var">flatten_co</span></a></span></span><span> </span><span id="local-6989586621681115023"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115023"><span class="hs-identifier hs-var">co</span></a></span></span><span>
</span><span id="line-1218"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681115022"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115022"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS CoercionN -&gt; FlatM CoercionN
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS CoercionN -&gt; FlatM CoercionN)
-&gt; TcS CoercionN -&gt; FlatM CoercionN
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; TcS CoercionN
</span><a href="GHC.Tc.Solver.Monad.html#zonkCo"><span class="hs-identifier hs-var">zonkCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115023"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-1219"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681115020"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115020"><span class="hs-identifier hs-var">env_role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1220"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681115019"><span class="annot"><span class="annottext">co' :: CoercionN
</span><a href="#local-6989586621681115019"><span class="hs-identifier hs-var hs-var">co'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcReflCo"><span class="hs-identifier hs-var">mkTcReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681115020"><span class="hs-identifier hs-var">env_role</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCoercionTy"><span class="hs-identifier hs-var">mkCoercionTy</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115022"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1221"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(CoercionN, CoercionN) -&gt; FlatM (CoercionN, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115022"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115019"><span class="hs-identifier hs-var">co'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1222"></span><span>
</span><span id="line-1223"></span><span class="hs-comment">-- flatten (nested) AppTys</span><span>
</span><span id="line-1224"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_app_tys"><span class="hs-identifier hs-type">flatten_app_tys</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1225"></span><span class="hs-comment">-- commoning up nested applications allows us to look up the function's kind</span><span>
</span><span id="line-1226"></span><span class="hs-comment">-- only once. Without commoning up like this, we would spend a quadratic amount</span><span>
</span><span id="line-1227"></span><span class="hs-comment">-- of time looking up functions' types</span><span>
</span><span id="line-1228"></span><span id="flatten_app_tys"><span class="annot"><span class="annottext">flatten_app_tys :: TcType -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_tys"><span class="hs-identifier hs-var hs-var">flatten_app_tys</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#AppTy"><span class="hs-identifier hs-type">AppTy</span></a></span><span> </span><span id="local-6989586621681115017"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115017"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span id="local-6989586621681115016"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115016"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681115015"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115015"><span class="hs-identifier hs-var">tys</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_tys"><span class="hs-identifier hs-var">flatten_app_tys</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115017"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115016"><span class="hs-identifier hs-var">ty2</span></a></span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; [TcType]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115015"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1229"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_app_tys"><span class="hs-identifier hs-var">flatten_app_tys</span></a></span><span> </span><span id="local-6989586621681115014"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115014"><span class="hs-identifier hs-var">fun_ty</span></a></span></span><span> </span><span id="local-6989586621681115013"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115013"><span class="hs-identifier hs-var">arg_tys</span></a></span></span><span>
</span><span id="line-1230"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115012"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115012"><span class="hs-identifier hs-var">fun_xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115011"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115011"><span class="hs-identifier hs-var">fun_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115014"><span class="hs-identifier hs-var">fun_ty</span></a></span><span>
</span><span id="line-1231"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_ty_args"><span class="hs-identifier hs-var">flatten_app_ty_args</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115012"><span class="hs-identifier hs-var">fun_xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115011"><span class="hs-identifier hs-var">fun_co</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115013"><span class="hs-identifier hs-var">arg_tys</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1232"></span><span>
</span><span id="line-1233"></span><span class="hs-comment">-- Given a flattened function (with the coercion produced by flattening) and</span><span>
</span><span id="line-1234"></span><span class="hs-comment">-- a bunch of unflattened arguments, flatten the arguments and apply.</span><span>
</span><span id="line-1235"></span><span class="hs-comment">-- The coercion argument's role matches the role stored in the FlatM monad.</span><span>
</span><span id="line-1236"></span><span class="hs-comment">--</span><span>
</span><span id="line-1237"></span><span class="hs-comment">-- The bang patterns used here were observed to improve performance. If you</span><span>
</span><span id="line-1238"></span><span class="hs-comment">-- wish to remove them, be sure to check for regeressions in allocations.</span><span>
</span><span id="line-1239"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_app_ty_args"><span class="hs-identifier hs-type">flatten_app_ty_args</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1240"></span><span id="flatten_app_ty_args"><span class="annot"><span class="annottext">flatten_app_ty_args :: TcType -&gt; CoercionN -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_ty_args"><span class="hs-identifier hs-var hs-var">flatten_app_ty_args</span></a></span></span><span> </span><span id="local-6989586621681115009"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115009"><span class="hs-identifier hs-var">fun_xi</span></a></span></span><span> </span><span id="local-6989586621681115008"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115008"><span class="hs-identifier hs-var">fun_co</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-1241"></span><span>  </span><span class="hs-comment">-- this will be a common case when called from flatten_fam_app, so shortcut</span><span>
</span><span id="line-1242"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115009"><span class="hs-identifier hs-var">fun_xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115008"><span class="hs-identifier hs-var">fun_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1243"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_app_ty_args"><span class="hs-identifier hs-var">flatten_app_ty_args</span></a></span><span> </span><span id="local-6989586621681115007"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115007"><span class="hs-identifier hs-var">fun_xi</span></a></span></span><span> </span><span id="local-6989586621681115006"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115006"><span class="hs-identifier hs-var">fun_co</span></a></span></span><span> </span><span id="local-6989586621681115005"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115005"><span class="hs-identifier hs-var">arg_tys</span></a></span></span><span>
</span><span id="line-1244"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115004"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115004"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115003"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115003"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681115002"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115002"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HasCallStack =&gt; TcType -&gt; Maybe (TyCon, [TcType])
TcType -&gt; Maybe (TyCon, [TcType])
</span><a href="GHC.Core.Type.html#tcSplitTyConApp_maybe"><span class="hs-identifier hs-var">tcSplitTyConApp_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115007"><span class="hs-identifier hs-var">fun_xi</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1245"></span><span>           </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681115000"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115000"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114999"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114999"><span class="hs-identifier hs-var">xis</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1246"></span><span>             </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114998"><span class="annot"><span class="annottext">tc_roles :: [Role]
</span><a href="#local-6989586621681114998"><span class="hs-identifier hs-var hs-var">tc_roles</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [Role]
</span><a href="GHC.Core.Coercion.html#tyConRolesRepresentational"><span class="hs-identifier hs-var">tyConRolesRepresentational</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115000"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1247"></span><span>                      </span><span id="local-6989586621681114996"><span class="annot"><span class="annottext">arg_roles :: [Role]
</span><a href="#local-6989586621681114996"><span class="hs-identifier hs-var hs-var">arg_roles</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; [Role] -&gt; [Role]
forall b a. [b] -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#dropList"><span class="hs-identifier hs-var">dropList</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114999"><span class="hs-identifier hs-var">xis</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681114998"><span class="hs-identifier hs-var">tc_roles</span></a></span><span>
</span><span id="line-1248"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114994"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114994"><span class="hs-identifier hs-var">arg_xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114993"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114993"><span class="hs-identifier hs-var">arg_cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114992"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114992"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1249"></span><span>                    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_vector"><span class="hs-identifier hs-var">flatten_vector</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; TcType -&gt; TcType
TcType -&gt; TcType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115007"><span class="hs-identifier hs-var">fun_xi</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681114996"><span class="hs-identifier hs-var">arg_roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115005"><span class="hs-identifier hs-var">arg_tys</span></a></span><span>
</span><span id="line-1250"></span><span>
</span><span id="line-1251"></span><span>                  </span><span class="hs-comment">-- Here, we have fun_co :: T xi1 xi2 ~ ty</span><span>
</span><span id="line-1252"></span><span>                  </span><span class="hs-comment">-- and we need to apply fun_co to the arg_cos. The problem is</span><span>
</span><span id="line-1253"></span><span>                  </span><span class="hs-comment">-- that using mkAppCo is wrong because that function expects</span><span>
</span><span id="line-1254"></span><span>                  </span><span class="hs-comment">-- its second coercion to be Nominal, and the arg_cos might</span><span>
</span><span id="line-1255"></span><span>                  </span><span class="hs-comment">-- not be. The solution is to use transitivity:</span><span>
</span><span id="line-1256"></span><span>                  </span><span class="hs-comment">-- T &lt;xi1&gt; &lt;xi2&gt; arg_cos ;; fun_co &lt;arg_tys&gt;</span><span>
</span><span id="line-1257"></span><span>                </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114989"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114989"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-1258"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114988"><span class="annot"><span class="annottext">app_xi :: TcType
</span><a href="#local-6989586621681114988"><span class="hs-identifier hs-var hs-var">app_xi</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115000"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114999"><span class="hs-identifier hs-var">xis</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; [TcType] -&gt; [TcType]
forall {a}. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114994"><span class="hs-identifier hs-var">arg_xis</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1259"></span><span>                      </span><span id="local-6989586621681114986"><span class="annot"><span class="annottext">app_co :: CoercionN
</span><a href="#local-6989586621681114986"><span class="hs-identifier hs-var hs-var">app_co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114989"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1260"></span><span>                        </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkAppCos"><span class="hs-identifier hs-var">mkAppCos</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115006"><span class="hs-identifier hs-var">fun_co</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114993"><span class="hs-identifier hs-var">arg_cos</span></a></span><span>
</span><span id="line-1261"></span><span>                        </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TyCon -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcTyConAppCo"><span class="hs-identifier hs-var">mkTcTyConAppCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Representational"><span class="hs-identifier hs-var">Representational</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681115000"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1262"></span><span>                                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Role -&gt; TcType -&gt; CoercionN) -&gt; [Role] -&gt; [TcType] -&gt; [CoercionN]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><a href="../../base/src/GHC.List.html#zipWith"><span class="hs-identifier hs-var">zipWith</span></a></span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkReflCo"><span class="hs-identifier hs-var">mkReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681114998"><span class="hs-identifier hs-var">tc_roles</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114999"><span class="hs-identifier hs-var">xis</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN] -&gt; [CoercionN] -&gt; [CoercionN]
forall {a}. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114993"><span class="hs-identifier hs-var">arg_cos</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1263"></span><span>                                  </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcTransCo"><span class="hs-operator hs-var">`mkTcTransCo`</span></a></span><span>
</span><span id="line-1264"></span><span>                                  </span><span class="annot"><span class="annottext">CoercionN -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkAppCos"><span class="hs-identifier hs-var">mkAppCos</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115006"><span class="hs-identifier hs-var">fun_co</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TcType -&gt; CoercionN) -&gt; [TcType] -&gt; [CoercionN]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkNomReflCo"><span class="hs-identifier hs-var">mkNomReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115005"><span class="hs-identifier hs-var">arg_tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1265"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN, CoercionN)
-&gt; FlatM (TcType, CoercionN, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114988"><span class="hs-identifier hs-var">app_xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114986"><span class="hs-identifier hs-var">app_co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114992"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1266"></span><span>           </span><span class="annot"><span class="annottext">Maybe (TyCon, [TcType])
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1267"></span><span>             </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114981"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114981"><span class="hs-identifier hs-var">arg_xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114980"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114980"><span class="hs-identifier hs-var">arg_cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114979"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114979"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1268"></span><span>                    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_vector"><span class="hs-identifier hs-var">flatten_vector</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; TcType -&gt; TcType
TcType -&gt; TcType
</span><a href="GHC.Core.Type.html#tcTypeKind"><span class="hs-identifier hs-var">tcTypeKind</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115007"><span class="hs-identifier hs-var">fun_xi</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; [Role]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681115005"><span class="hs-identifier hs-var">arg_tys</span></a></span><span>
</span><span id="line-1269"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114978"><span class="annot"><span class="annottext">arg_xi :: TcType
</span><a href="#local-6989586621681114978"><span class="hs-identifier hs-var hs-var">arg_xi</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.Type.html#mkAppTys"><span class="hs-identifier hs-var">mkAppTys</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115007"><span class="hs-identifier hs-var">fun_xi</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114981"><span class="hs-identifier hs-var">arg_xis</span></a></span><span>
</span><span id="line-1270"></span><span>                      </span><span id="local-6989586621681114977"><span class="annot"><span class="annottext">arg_co :: CoercionN
</span><a href="#local-6989586621681114977"><span class="hs-identifier hs-var hs-var">arg_co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkAppCos"><span class="hs-identifier hs-var">mkAppCos</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115006"><span class="hs-identifier hs-var">fun_co</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114980"><span class="hs-identifier hs-var">arg_cos</span></a></span><span>
</span><span id="line-1271"></span><span>                </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN, CoercionN)
-&gt; FlatM (TcType, CoercionN, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114978"><span class="hs-identifier hs-var">arg_xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114977"><span class="hs-identifier hs-var">arg_co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114979"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1272"></span><span>
</span><span id="line-1273"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114976"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114976"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1274"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; Role -&gt; CoercionN -&gt; (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#homogenise_result"><span class="hs-identifier hs-var">homogenise_result</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681115004"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115003"><span class="hs-identifier hs-var">co</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114976"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681115002"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1275"></span><span>
</span><span id="line-1276"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_ty_con_app"><span class="hs-identifier hs-type">flatten_ty_con_app</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1277"></span><span id="flatten_ty_con_app"><span class="annot"><span class="annottext">flatten_ty_con_app :: TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_ty_con_app"><span class="hs-identifier hs-var hs-var">flatten_ty_con_app</span></a></span></span><span> </span><span id="local-6989586621681114974"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114974"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681114973"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114973"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-1278"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114972"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114972"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1279"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114971"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114971"><span class="hs-identifier hs-var">xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114970"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114970"><span class="hs-identifier hs-var">cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114969"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114969"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-identifier hs-var">flatten_args_tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114974"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; TyCon -&gt; [Role]
</span><a href="GHC.Core.Coercion.html#tyConRolesX"><span class="hs-identifier hs-var">tyConRolesX</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114972"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114974"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114973"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1280"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114967"><span class="annot"><span class="annottext">tyconapp_xi :: TcType
</span><a href="#local-6989586621681114967"><span class="hs-identifier hs-var hs-var">tyconapp_xi</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114974"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114971"><span class="hs-identifier hs-var">xis</span></a></span><span>
</span><span id="line-1281"></span><span>             </span><span id="local-6989586621681114965"><span class="annot"><span class="annottext">tyconapp_co :: CoercionN
</span><a href="#local-6989586621681114965"><span class="hs-identifier hs-var hs-var">tyconapp_co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Role -&gt; TyCon -&gt; [CoercionN] -&gt; CoercionN
Role -&gt; TyCon -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTyConAppCo"><span class="hs-identifier hs-var">mkTyConAppCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114972"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114974"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114970"><span class="hs-identifier hs-var">cos</span></a></span><span>
</span><span id="line-1282"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; Role -&gt; CoercionN -&gt; (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#homogenise_result"><span class="hs-identifier hs-var">homogenise_result</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114967"><span class="hs-identifier hs-var">tyconapp_xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114965"><span class="hs-identifier hs-var">tyconapp_co</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114972"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114969"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1283"></span><span>
</span><span id="line-1284"></span><span class="hs-comment">-- Make the result of flattening homogeneous (Note [Flattening] (F2))</span><span>
</span><span id="line-1285"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#homogenise_result"><span class="hs-identifier hs-type">homogenise_result</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span>              </span><span class="hs-comment">-- a flattened type</span><span>
</span><span id="line-1286"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span>        </span><span class="hs-comment">-- :: xi ~r original ty</span><span>
</span><span id="line-1287"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span>            </span><span class="hs-comment">-- r</span><span>
</span><span id="line-1288"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span>       </span><span class="hs-comment">-- kind_co :: tcTypeKind(xi) ~N tcTypeKind(ty)</span><span>
</span><span id="line-1289"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- (xi |&gt; kind_co, (xi |&gt; kind_co)</span><span>
</span><span id="line-1290"></span><span>                                     </span><span class="hs-comment">--   ~r original ty)</span><span>
</span><span id="line-1291"></span><span id="homogenise_result"><span class="annot"><span class="annottext">homogenise_result :: TcType -&gt; CoercionN -&gt; Role -&gt; CoercionN -&gt; (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#homogenise_result"><span class="hs-identifier hs-var hs-var">homogenise_result</span></a></span></span><span> </span><span id="local-6989586621681114963"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114963"><span class="hs-identifier hs-var">xi</span></a></span></span><span> </span><span id="local-6989586621681114962"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114962"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span id="local-6989586621681114961"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114961"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span id="local-6989586621681114960"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114960"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span>
</span><span id="line-1292"></span><span>  </span><span class="hs-comment">-- the explicit pattern match here improves the performance of T9872a, b, c by</span><span>
</span><span id="line-1293"></span><span>  </span><span class="hs-comment">-- ~2%</span><span>
</span><span id="line-1294"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; Bool
</span><a href="GHC.Core.Coercion.html#isGReflCo"><span class="hs-identifier hs-var">isGReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114960"><span class="hs-identifier hs-var">kind_co</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114963"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114960"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114962"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1295"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114963"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114960"><span class="hs-identifier hs-var">kind_co</span></a></span><span>
</span><span id="line-1296"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">(CoercionN -&gt; CoercionN) -&gt; CoercionN -&gt; CoercionN
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; MCoercionN -&gt; CoercionN
</span><a href="GHC.Core.TyCo.Rep.html#GRefl"><span class="hs-identifier hs-var">GRefl</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114961"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114963"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; MCoercionN
</span><a href="GHC.Core.TyCo.Rep.html#MCo"><span class="hs-identifier hs-var">MCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114960"><span class="hs-identifier hs-var">kind_co</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114962"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1297"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#homogenise_result"><span class="hs-pragma hs-type">homogenise_result</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1298"></span><span>
</span><span id="line-1299"></span><span class="hs-comment">-- Flatten a vector (list of arguments).</span><span>
</span><span id="line-1300"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_vector"><span class="hs-identifier hs-type">flatten_vector</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Kind"><span class="hs-identifier hs-type">Kind</span></a></span><span>   </span><span class="hs-comment">-- of the function being applied to these arguments</span><span>
</span><span id="line-1301"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#Role"><span class="hs-identifier hs-type">Role</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- If we're flatten w.r.t. ReprEq, what roles do the</span><span>
</span><span id="line-1302"></span><span>                         </span><span class="hs-comment">-- args have?</span><span>
</span><span id="line-1303"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- the args to flatten</span><span>
</span><span id="line-1304"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1305"></span><span id="flatten_vector"><span class="annot"><span class="annottext">flatten_vector :: TcType
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_vector"><span class="hs-identifier hs-var hs-var">flatten_vector</span></a></span></span><span> </span><span id="local-6989586621681114954"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114954"><span class="hs-identifier hs-var">ki</span></a></span></span><span> </span><span id="local-6989586621681114953"><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681114953"><span class="hs-identifier hs-var">roles</span></a></span></span><span> </span><span id="local-6989586621681114952"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114952"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-1306"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114951"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114951"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-1307"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114951"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1308"></span><span>           </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; Bool
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-identifier hs-var">flatten_args</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114950"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-1309"></span><span>                                  </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114949"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span><span>
</span><span id="line-1310"></span><span>                                  </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114948"><span class="hs-identifier hs-var">inner_ki</span></a></span><span>
</span><span id="line-1311"></span><span>                                  </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681114947"><span class="hs-identifier hs-var">fvs</span></a></span><span>
</span><span id="line-1312"></span><span>                                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; [Role]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1313"></span><span>                                  </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114952"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1314"></span><span>           </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
-&gt; Bool
-&gt; TcType
-&gt; TcTyCoVarSet
-&gt; [Role]
-&gt; [TcType]
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args"><span class="hs-identifier hs-var">flatten_args</span></a></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114950"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-1315"></span><span>                                  </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114949"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span><span>
</span><span id="line-1316"></span><span>                                  </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114948"><span class="hs-identifier hs-var">inner_ki</span></a></span><span>
</span><span id="line-1317"></span><span>                                  </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681114947"><span class="hs-identifier hs-var">fvs</span></a></span><span>
</span><span id="line-1318"></span><span>                                  </span><span class="annot"><span class="annottext">[Role]
</span><a href="#local-6989586621681114953"><span class="hs-identifier hs-var">roles</span></a></span><span>
</span><span id="line-1319"></span><span>                                  </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114952"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1320"></span><span>       </span><span class="hs-special">}</span><span>
</span><span id="line-1321"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1322"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621681114950"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114950"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114948"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114948"><span class="hs-identifier hs-var">inner_ki</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114949"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114949"><span class="hs-identifier hs-var">any_named_bndrs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="GHC.Tc.Solver.Flatten.html#split_pi_tys%27"><span class="hs-identifier hs-var">split_pi_tys'</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114954"><span class="hs-identifier hs-var">ki</span></a></span><span>
</span><span id="line-1323"></span><span>    </span><span id="local-6989586621681114947"><span class="annot"><span class="annottext">fvs :: TcTyCoVarSet
</span><a href="#local-6989586621681114947"><span class="hs-identifier hs-var hs-var">fvs</span></a></span></span><span>                                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcTyCoVarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfType"><span class="hs-identifier hs-var">tyCoVarsOfType</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114954"><span class="hs-identifier hs-var">ki</span></a></span><span>
</span><span id="line-1324"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_vector"><span class="hs-pragma hs-type">flatten_vector</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1325"></span><span>
</span><span id="line-1326"></span><span class="hs-comment">{-
Note [Flattening synonyms]
~~~~~~~~~~~~~~~~~~~~~~~~~~
Not expanding synonyms aggressively improves error messages, and
keeps types smaller. But we need to take care.

Suppose
   type T a = a -&gt; a
and we want to flatten the type (T (F a)).  Then we can safely flatten
the (F a) to a skolem, and return (T fsk).  We don't need to expand the
synonym.  This works because TcTyConAppCo can deal with synonyms
(unlike TyConAppCo), see Note [TcCoercions] in GHC.Tc.Types.Evidence.

But (#8979) for
   type T a = (F a, a)    where F is a type function
we must expand the synonym in (say) T Int, to expose the type function
to the flattener.


Note [Flattening under a forall]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Under a forall, we
  (a) MUST apply the inert substitution
  (b) MUST NOT flatten type family applications
Hence FMSubstOnly.

For (a) consider   c ~ a, a ~ T (forall b. (b, [c]))
If we don't apply the c~a substitution to the second constraint
we won't see the occurs-check error.

For (b) consider  (a ~ forall b. F a b), we don't want to flatten
to     (a ~ forall b.fsk, F a b ~ fsk)
because now the 'b' has escaped its scope.  We'd have to flatten to
       (a ~ forall b. fsk b, forall b. F a b ~ fsk b)
and we have not begun to think about how to make that work!

************************************************************************
*                                                                      *
             Flattening a type-family application
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1368"></span><span>
</span><span id="line-1369"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_fam_app"><span class="hs-identifier hs-type">flatten_fam_app</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1370"></span><span>  </span><span class="hs-comment">--   flatten_fam_app            can be over-saturated</span><span>
</span><span id="line-1371"></span><span>  </span><span class="hs-comment">--   flatten_exact_fam_app       is exactly saturated</span><span>
</span><span id="line-1372"></span><span>  </span><span class="hs-comment">--   flatten_exact_fam_app_fully lifts out the application to top level</span><span>
</span><span id="line-1373"></span><span>  </span><span class="hs-comment">-- Postcondition: Coercion :: Xi ~ F tys</span><span>
</span><span id="line-1374"></span><span id="flatten_fam_app"><span class="annot"><span class="annottext">flatten_fam_app :: TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_fam_app"><span class="hs-identifier hs-var hs-var">flatten_fam_app</span></a></span></span><span> </span><span id="local-6989586621681114945"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114945"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681114944"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114944"><span class="hs-identifier hs-var">tys</span></a></span></span><span>  </span><span class="hs-comment">-- Can be over-saturated</span><span>
</span><span id="line-1375"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">tys</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">lengthAtLeast</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">tyConArity</span><span> </span><span class="hs-identifier">tc</span><span>
</span><span id="line-1376"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tc</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">tyConArity</span><span> </span><span class="hs-identifier">tc</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tys</span><span class="hs-special">)</span><span>
</span><span id="line-1377"></span><span>
</span><span id="line-1378"></span><span>      </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114938"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681114938"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span>
</span><span id="line-1379"></span><span>         </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681114938"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1380"></span><span>             </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_SubstOnly"><span class="hs-identifier hs-var">FM_SubstOnly</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_ty_con_app"><span class="hs-identifier hs-var">flatten_ty_con_app</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114945"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114944"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1381"></span><span>             </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#FM_FlattenAll"><span class="hs-identifier hs-var">FM_FlattenAll</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1382"></span><span>
</span><span id="line-1383"></span><span>                 </span><span class="hs-comment">-- Type functions are saturated</span><span>
</span><span id="line-1384"></span><span>                 </span><span class="hs-comment">-- The type function might be *over* saturated</span><span>
</span><span id="line-1385"></span><span>                 </span><span class="hs-comment">-- in which case the remaining arguments should</span><span>
</span><span id="line-1386"></span><span>                 </span><span class="hs-comment">-- be dealt with by AppTys</span><span>
</span><span id="line-1387"></span><span>      </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114937"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114937"><span class="hs-identifier hs-var">tys1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114936"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114936"><span class="hs-identifier hs-var">tys_rest</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; [TcType] -&gt; ([TcType], [TcType])
forall a. Arity -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/GHC.List.html#splitAt"><span class="hs-identifier hs-var">splitAt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Arity
</span><a href="GHC.Core.TyCon.html#tyConArity"><span class="hs-identifier hs-var hs-var">tyConArity</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114945"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114944"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1388"></span><span>         </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114934"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114934"><span class="hs-identifier hs-var">xi1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114933"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114933"><span class="hs-identifier hs-var">co1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_exact_fam_app_fully"><span class="hs-identifier hs-var">flatten_exact_fam_app_fully</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114945"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114937"><span class="hs-identifier hs-var">tys1</span></a></span><span>
</span><span id="line-1389"></span><span>               </span><span class="hs-comment">-- co1 :: xi1 ~ F tys1</span><span>
</span><span id="line-1390"></span><span>
</span><span id="line-1391"></span><span>         </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_app_ty_args"><span class="hs-identifier hs-var">flatten_app_ty_args</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114934"><span class="hs-identifier hs-var">xi1</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114933"><span class="hs-identifier hs-var">co1</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114936"><span class="hs-identifier hs-var">tys_rest</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1392"></span><span>
</span><span id="line-1393"></span><span class="hs-comment">-- the [TcType] exactly saturate the TyCon</span><span>
</span><span id="line-1394"></span><span class="hs-comment">-- See note [flatten_exact_fam_app_fully performance]</span><span>
</span><span id="line-1395"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_exact_fam_app_fully"><span class="hs-identifier hs-type">flatten_exact_fam_app_fully</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1396"></span><span id="flatten_exact_fam_app_fully"><span class="annot"><span class="annottext">flatten_exact_fam_app_fully :: TyCon -&gt; [TcType] -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_exact_fam_app_fully"><span class="hs-identifier hs-var hs-var">flatten_exact_fam_app_fully</span></a></span></span><span> </span><span id="local-6989586621681114931"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681114930"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114930"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-1397"></span><span>  </span><span class="hs-comment">-- See Note [Reduce type family applications eagerly]</span><span>
</span><span id="line-1398"></span><span>     </span><span class="hs-comment">-- the following tcTypeKind should never be evaluated, as it's just used in</span><span>
</span><span id="line-1399"></span><span>     </span><span class="hs-comment">-- casting, and casts by refl are dropped</span><span>
</span><span id="line-1400"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114929"><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="#local-6989586621681114929"><span class="hs-identifier hs-var">mOut</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; FlatM (Maybe (TcType, CoercionN))
</span><a href="#local-6989586621681114928"><span class="hs-identifier hs-var">try_to_reduce_nocache</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114930"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1401"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="#local-6989586621681114929"><span class="hs-identifier hs-var">mOut</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1402"></span><span>           </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114927"><span class="annot"><span class="annottext">(TcType, CoercionN)
</span><a href="#local-6989586621681114927"><span class="hs-identifier hs-var">out</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN)
</span><a href="#local-6989586621681114927"><span class="hs-identifier hs-var">out</span></a></span><span>
</span><span id="line-1403"></span><span>           </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1404"></span><span>               </span><span class="hs-special">{</span><span> </span><span class="hs-comment">-- First, flatten the arguments</span><span>
</span><span id="line-1405"></span><span>               </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114926"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114925"><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114925"><span class="hs-identifier hs-var">cos</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114924"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1406"></span><span>                   </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">EqRel
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
forall a. EqRel -&gt; FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#setEqRel"><span class="hs-identifier hs-var">setEqRel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM ([TcType], [CoercionN], CoercionN)
 -&gt; FlatM ([TcType], [CoercionN], CoercionN))
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
-&gt; FlatM ([TcType], [CoercionN], CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>  </span><span class="hs-comment">-- just do this once, instead of for</span><span>
</span><span id="line-1407"></span><span>                                        </span><span class="hs-comment">-- each arg</span><span>
</span><span id="line-1408"></span><span>                      </span><span class="annot"><span class="annottext">TyCon
-&gt; [Role] -&gt; [TcType] -&gt; FlatM ([TcType], [CoercionN], CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_args_tc"><span class="hs-identifier hs-var">flatten_args_tc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; [Role]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Nominal"><span class="hs-identifier hs-var">Nominal</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114930"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1409"></span><span>                      </span><span class="hs-comment">-- kind_co :: tcTypeKind(F xis) ~N tcTypeKind(F tys)</span><span>
</span><span id="line-1410"></span><span>               </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114923"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114923"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span>   </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-1411"></span><span>               </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114922"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114922"><span class="hs-identifier hs-var">cur_flav</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavour"><span class="hs-identifier hs-var">getFlavour</span></a></span><span>
</span><span id="line-1412"></span><span>               </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114921"><span class="annot"><span class="annottext">role :: Role
</span><a href="#local-6989586621681114921"><span class="hs-keyword hs-var hs-var">role</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; Role
</span><a href="GHC.Core.Predicate.html#eqRelRole"><span class="hs-identifier hs-var">eqRelRole</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114923"><span class="hs-identifier hs-var">eq_rel</span></a></span><span>
</span><span id="line-1413"></span><span>                     </span><span id="local-6989586621681114919"><span class="annot"><span class="annottext">ret_co :: CoercionN
</span><a href="#local-6989586621681114919"><span class="hs-identifier hs-var hs-var">ret_co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Role -&gt; TyCon -&gt; [CoercionN] -&gt; CoercionN
Role -&gt; TyCon -&gt; [CoercionN] -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTyConAppCo"><span class="hs-identifier hs-var">mkTyConAppCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114921"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[CoercionN]
</span><a href="#local-6989586621681114925"><span class="hs-identifier hs-var">cos</span></a></span><span>
</span><span id="line-1414"></span><span>                      </span><span class="hs-comment">-- ret_co :: F xis ~ F tys; might be heterogeneous</span><span>
</span><span id="line-1415"></span><span>
</span><span id="line-1416"></span><span>                </span><span class="hs-comment">-- Now, look in the cache</span><span>
</span><span id="line-1417"></span><span>               </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114918"><span class="annot"><span class="annottext">Maybe (CoercionN, TcType, CtFlavour)
</span><a href="#local-6989586621681114918"><span class="hs-identifier hs-var">mb_ct</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (Maybe (CoercionN, TcType, CtFlavour))
-&gt; FlatM (Maybe (CoercionN, TcType, CtFlavour))
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (Maybe (CoercionN, TcType, CtFlavour))
 -&gt; FlatM (Maybe (CoercionN, TcType, CtFlavour)))
-&gt; TcS (Maybe (CoercionN, TcType, CtFlavour))
-&gt; FlatM (Maybe (CoercionN, TcType, CtFlavour))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcS (Maybe (CoercionN, TcType, CtFlavour))
</span><a href="GHC.Tc.Solver.Monad.html#lookupFlatCache"><span class="hs-identifier hs-var">lookupFlatCache</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span>
</span><span id="line-1418"></span><span>               </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType, CtFlavour)
</span><a href="#local-6989586621681114918"><span class="hs-identifier hs-var">mb_ct</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1419"></span><span>                   </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114916"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114916"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114915"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114915"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114914"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114914"><span class="hs-identifier hs-var">flav</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- co :: F xis ~ fsk</span><span>
</span><span id="line-1420"></span><span>                        </span><span class="hs-comment">-- flav is [G] or [WD]</span><span>
</span><span id="line-1421"></span><span>                        </span><span class="hs-comment">-- See Note [Type family equations] in GHC.Tc.Solver.Monad</span><span>
</span><span id="line-1422"></span><span>                     </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SwapFlag
</span><a href="GHC.Types.Basic.html#NotSwapped"><span class="hs-identifier hs-var">NotSwapped</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114914"><span class="hs-identifier hs-var">flav</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour -&gt; CtFlavour -&gt; (SwapFlag, Bool)
</span><a href="GHC.Tc.Types.Constraint.html#funEqCanDischargeF"><span class="hs-operator hs-var">`funEqCanDischargeF`</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114922"><span class="hs-identifier hs-var">cur_flav</span></a></span><span>
</span><span id="line-1423"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span>  </span><span class="hs-comment">-- Usable hit in the flat-cache</span><span>
</span><span id="line-1424"></span><span>                        </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten/flat-cache hit&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; FlatM ()) -&gt; SDoc -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1425"></span><span>                               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114915"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1426"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114911"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114911"><span class="hs-identifier hs-var">fsk_xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114910"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114910"><span class="hs-identifier hs-var">fsk_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114915"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span>
</span><span id="line-1427"></span><span>                                  </span><span class="hs-comment">-- The fsk may already have been unified, so</span><span>
</span><span id="line-1428"></span><span>                                  </span><span class="hs-comment">-- flatten it</span><span>
</span><span id="line-1429"></span><span>                                  </span><span class="hs-comment">-- fsk_co :: fsk_xi ~ fsk</span><span>
</span><span id="line-1430"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114909"><span class="annot"><span class="annottext">xi :: TcType
</span><a href="#local-6989586621681114909"><span class="hs-identifier hs-var hs-var">xi</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114911"><span class="hs-identifier hs-var">fsk_xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span><span>
</span><span id="line-1431"></span><span>                                 </span><span id="local-6989586621681114908"><span class="annot"><span class="annottext">co' :: CoercionN
</span><a href="#local-6989586621681114908"><span class="hs-identifier hs-var hs-var">co'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcCoherenceLeftCo"><span class="hs-identifier hs-var">mkTcCoherenceLeftCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114921"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114911"><span class="hs-identifier hs-var">fsk_xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114910"><span class="hs-identifier hs-var">fsk_co</span></a></span><span>
</span><span id="line-1432"></span><span>                                       </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span>
</span><span id="line-1433"></span><span>                                       </span><span class="annot"><span class="annottext">EqRel -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#maybeTcSubCo"><span class="hs-identifier hs-var">maybeTcSubCo</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114923"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114916"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1434"></span><span>                                       </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114919"><span class="hs-identifier hs-var">ret_co</span></a></span><span>
</span><span id="line-1435"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114909"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114908"><span class="hs-identifier hs-var">co'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1436"></span><span>                           </span><span class="hs-special">}</span><span>
</span><span id="line-1437"></span><span>                                            </span><span class="hs-comment">-- :: fsk_xi ~ F xis</span><span>
</span><span id="line-1438"></span><span>
</span><span id="line-1439"></span><span>                   </span><span class="hs-comment">-- Try to reduce the family application right now</span><span>
</span><span id="line-1440"></span><span>                   </span><span class="hs-comment">-- See Note [Reduce type family applications eagerly]</span><span>
</span><span id="line-1441"></span><span>                   </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType, CtFlavour)
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114905"><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="#local-6989586621681114905"><span class="hs-identifier hs-var">mOut</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TyCon
-&gt; [TcType]
-&gt; CoercionN
-&gt; (CoercionN -&gt; CoercionN)
-&gt; FlatM (Maybe (TcType, CoercionN))
</span><a href="#local-6989586621681114904"><span class="hs-identifier hs-var">try_to_reduce</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1442"></span><span>                                                   </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span>
</span><span id="line-1443"></span><span>                                                   </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span><span>
</span><span id="line-1444"></span><span>                                                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114919"><span class="hs-identifier hs-var">ret_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1445"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="#local-6989586621681114905"><span class="hs-identifier hs-var">mOut</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1446"></span><span>                               </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114903"><span class="annot"><span class="annottext">(TcType, CoercionN)
</span><a href="#local-6989586621681114903"><span class="hs-identifier hs-var">out</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN)
</span><a href="#local-6989586621681114903"><span class="hs-identifier hs-var">out</span></a></span><span>
</span><span id="line-1447"></span><span>                               </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1448"></span><span>                                 </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114902"><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681114902"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtLoc
</span><a href="GHC.Tc.Solver.Flatten.html#getLoc"><span class="hs-identifier hs-var">getLoc</span></a></span><span>
</span><span id="line-1449"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114901"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114901"><span class="hs-identifier hs-var">ev</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114900"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114900"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114899"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114899"><span class="hs-identifier hs-var">fsk</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (CtEvidence, CoercionN, TcTyVar)
-&gt; FlatM (CtEvidence, CoercionN, TcTyVar)
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (CtEvidence, CoercionN, TcTyVar)
 -&gt; FlatM (CtEvidence, CoercionN, TcTyVar))
-&gt; TcS (CtEvidence, CoercionN, TcTyVar)
-&gt; FlatM (CtEvidence, CoercionN, TcTyVar)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1450"></span><span>                                     </span><span class="annot"><span class="annottext">CtFlavour
-&gt; CtLoc
-&gt; TyCon
-&gt; [TcType]
-&gt; TcS (CtEvidence, CoercionN, TcTyVar)
</span><a href="GHC.Tc.Solver.Monad.html#newFlattenSkolem"><span class="hs-identifier hs-var">newFlattenSkolem</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114922"><span class="hs-identifier hs-var">cur_flav</span></a></span><span> </span><span class="annot"><span class="annottext">CtLoc
</span><a href="#local-6989586621681114902"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span>
</span><span id="line-1451"></span><span>
</span><span id="line-1452"></span><span>                                 </span><span class="hs-comment">-- The new constraint (F xis ~ fsk) is not</span><span>
</span><span id="line-1453"></span><span>                                 </span><span class="hs-comment">-- necessarily inert (e.g. the LHS may be a</span><span>
</span><span id="line-1454"></span><span>                                 </span><span class="hs-comment">-- redex) so we must put it in the work list</span><span>
</span><span id="line-1455"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114897"><span class="annot"><span class="annottext">ct :: Ct
</span><a href="#local-6989586621681114897"><span class="hs-identifier hs-var hs-var">ct</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CFunEqCan :: CtEvidence -&gt; TyCon -&gt; [TcType] -&gt; TcTyVar -&gt; Ct
</span><a href="GHC.Tc.Types.Constraint.html#CFunEqCan"><span class="hs-identifier hs-type">CFunEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_ev :: CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114901"><span class="hs-identifier hs-var">ev</span></a></span><span>
</span><span id="line-1456"></span><span>                                                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_fun :: TyCon
</span><a href="GHC.Tc.Types.Constraint.html#cc_fun"><span class="hs-identifier hs-var">cc_fun</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-1457"></span><span>                                                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_tyargs :: [TcType]
</span><a href="GHC.Tc.Types.Constraint.html#cc_tyargs"><span class="hs-identifier hs-var">cc_tyargs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span>
</span><span id="line-1458"></span><span>                                                      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_fsk :: TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_fsk"><span class="hs-identifier hs-var">cc_fsk</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114899"><span class="hs-identifier hs-var">fsk</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1459"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Ct -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#emitFlatWork"><span class="hs-identifier hs-var">emitFlatWork</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114897"><span class="hs-identifier hs-var">ct</span></a></span><span>
</span><span id="line-1460"></span><span>
</span><span id="line-1461"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flatten/flat-cache miss&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; FlatM ()) -&gt; SDoc -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1462"></span><span>                                     </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114931"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114926"><span class="hs-identifier hs-var">xis</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114899"><span class="hs-identifier hs-var">fsk</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114901"><span class="hs-identifier hs-var">ev</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1463"></span><span>
</span><span id="line-1464"></span><span>                                 </span><span class="hs-comment">-- NB: fsk's kind is already flattened because</span><span>
</span><span id="line-1465"></span><span>                                 </span><span class="hs-comment">--     the xis are flattened</span><span>
</span><span id="line-1466"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114891"><span class="annot"><span class="annottext">fsk_ty :: TcType
</span><a href="#local-6989586621681114891"><span class="hs-identifier hs-var hs-var">fsk_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTy"><span class="hs-identifier hs-var">mkTyVarTy</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114899"><span class="hs-identifier hs-var">fsk</span></a></span><span>
</span><span id="line-1467"></span><span>                                       </span><span id="local-6989586621681114889"><span class="annot"><span class="annottext">xi :: TcType
</span><a href="#local-6989586621681114889"><span class="hs-identifier hs-var hs-var">xi</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114891"><span class="hs-identifier hs-var">fsk_ty</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span><span>
</span><span id="line-1468"></span><span>                                       </span><span id="local-6989586621681114888"><span class="annot"><span class="annottext">co' :: CoercionN
</span><a href="#local-6989586621681114888"><span class="hs-identifier hs-var hs-var">co'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcCoherenceLeftCo"><span class="hs-identifier hs-var">mkTcCoherenceLeftCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114921"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114891"><span class="hs-identifier hs-var">fsk_ty</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114924"><span class="hs-identifier hs-var">kind_co</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#maybeTcSubCo"><span class="hs-identifier hs-var">maybeTcSubCo</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114923"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114900"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1469"></span><span>                                             </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114919"><span class="hs-identifier hs-var">ret_co</span></a></span><span>
</span><span id="line-1470"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114889"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114888"><span class="hs-identifier hs-var">co'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1471"></span><span>                                 </span><span class="hs-special">}</span><span>
</span><span id="line-1472"></span><span>                           </span><span class="hs-special">}</span><span>
</span><span id="line-1473"></span><span>               </span><span class="hs-special">}</span><span>
</span><span id="line-1474"></span><span>        </span><span class="hs-special">}</span><span>
</span><span id="line-1475"></span><span>
</span><span id="line-1476"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1477"></span><span>
</span><span id="line-1478"></span><span>    </span><span class="hs-comment">-- try_to_reduce and try_to_reduce_nocache (below) could be unified into</span><span>
</span><span id="line-1479"></span><span>    </span><span class="hs-comment">-- a more general definition, but it was observed that separating them</span><span>
</span><span id="line-1480"></span><span>    </span><span class="hs-comment">-- gives better performance (lower allocation numbers in T9872x).</span><span>
</span><span id="line-1481"></span><span>
</span><span id="line-1482"></span><span>    </span><span class="annot"><a href="#local-6989586621681114904"><span class="hs-identifier hs-type">try_to_reduce</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>   </span><span class="hs-comment">-- F, family tycon</span><span>
</span><span id="line-1483"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- args, not necessarily flattened</span><span>
</span><span id="line-1484"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#CoercionN"><span class="hs-identifier hs-type">CoercionN</span></a></span><span> </span><span class="hs-comment">-- kind_co :: tcTypeKind(F args) ~N</span><span>
</span><span id="line-1485"></span><span>                               </span><span class="hs-comment">--            tcTypeKind(F orig_args)</span><span>
</span><span id="line-1486"></span><span>                               </span><span class="hs-comment">-- where</span><span>
</span><span id="line-1487"></span><span>                               </span><span class="hs-comment">-- orig_args is what was passed to the outer</span><span>
</span><span id="line-1488"></span><span>                               </span><span class="hs-comment">-- function</span><span>
</span><span id="line-1489"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span>   </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span>     </span><span class="hs-comment">-- :: (xi |&gt; kind_co) ~ F args</span><span>
</span><span id="line-1490"></span><span>                      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- what to return from outer function</span><span>
</span><span id="line-1491"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1492"></span><span>    </span><span id="local-6989586621681114904"><span class="annot"><span class="annottext">try_to_reduce :: TyCon
-&gt; [TcType]
-&gt; CoercionN
-&gt; (CoercionN -&gt; CoercionN)
-&gt; FlatM (Maybe (TcType, CoercionN))
</span><a href="#local-6989586621681114904"><span class="hs-identifier hs-var hs-var">try_to_reduce</span></a></span></span><span> </span><span id="local-6989586621681114887"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114887"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681114886"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114886"><span class="hs-identifier hs-var">tys</span></a></span></span><span> </span><span id="local-6989586621681114885"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114885"><span class="hs-identifier hs-var">kind_co</span></a></span></span><span> </span><span id="local-6989586621681114884"><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="#local-6989586621681114884"><span class="hs-identifier hs-var">update_co</span></a></span></span><span>
</span><span id="line-1493"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#checkStackDepth"><span class="hs-identifier hs-var">checkStackDepth</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114887"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114886"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1494"></span><span>           </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114883"><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="#local-6989586621681114883"><span class="hs-identifier hs-var">mb_match</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (Maybe (CoercionN, TcType))
-&gt; FlatM (Maybe (CoercionN, TcType))
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (Maybe (CoercionN, TcType))
 -&gt; FlatM (Maybe (CoercionN, TcType)))
-&gt; TcS (Maybe (CoercionN, TcType))
-&gt; FlatM (Maybe (CoercionN, TcType))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcS (Maybe (CoercionN, TcType))
</span><a href="GHC.Tc.Solver.Monad.html#matchFam"><span class="hs-identifier hs-var">matchFam</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114887"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114886"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1495"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="#local-6989586621681114883"><span class="hs-identifier hs-var">mb_match</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1496"></span><span>                 </span><span class="hs-comment">-- NB: norm_co will always be homogeneous. All type families</span><span>
</span><span id="line-1497"></span><span>                 </span><span class="hs-comment">-- are homogeneous.</span><span>
</span><span id="line-1498"></span><span>               </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114881"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114881"><span class="hs-identifier hs-var">norm_co</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114880"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114880"><span class="hs-identifier hs-var">norm_ty</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1499"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Eager T.F. reduction success&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; FlatM ()) -&gt; SDoc -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1500"></span><span>                         </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114887"><span class="hs-identifier hs-var">tc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114886"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114880"><span class="hs-identifier hs-var">norm_ty</span></a></span><span>
</span><span id="line-1501"></span><span>                              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114881"><span class="hs-identifier hs-var">norm_co</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#dcolon"><span class="hs-identifier hs-var">dcolon</span></a></span><span>
</span><span id="line-1502"></span><span>                                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Pair TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; Pair TcType
</span><a href="GHC.Core.Coercion.html#coercionKind"><span class="hs-identifier hs-var">coercionKind</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114881"><span class="hs-identifier hs-var">norm_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1503"></span><span>                              </span><span class="hs-special">]</span><span>
</span><span id="line-1504"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114877"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114877"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114876"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114876"><span class="hs-identifier hs-var">final_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#bumpDepth"><span class="hs-identifier hs-var">bumpDepth</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114880"><span class="hs-identifier hs-var">norm_ty</span></a></span><span>
</span><span id="line-1505"></span><span>                       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114875"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114875"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-1506"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114874"><span class="annot"><span class="annottext">co :: CoercionN
</span><a href="#local-6989586621681114874"><span class="hs-identifier hs-var hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#maybeTcSubCo"><span class="hs-identifier hs-var">maybeTcSubCo</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114875"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114881"><span class="hs-identifier hs-var">norm_co</span></a></span><span>
</span><span id="line-1507"></span><span>                                   </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114876"><span class="hs-identifier hs-var">final_co</span></a></span><span>
</span><span id="line-1508"></span><span>                       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114873"><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114873"><span class="hs-identifier hs-var">flavour</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtFlavour
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavour"><span class="hs-identifier hs-var">getFlavour</span></a></span><span>
</span><span id="line-1509"></span><span>                           </span><span class="hs-comment">-- NB: only extend cache with nominal equalities</span><span>
</span><span id="line-1510"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; FlatM () -&gt; FlatM ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114875"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; EqRel -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(FlatM () -&gt; FlatM ()) -&gt; FlatM () -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1511"></span><span>                         </span><span class="annot"><span class="annottext">TcS () -&gt; FlatM ()
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS () -&gt; FlatM ()) -&gt; TcS () -&gt; FlatM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1512"></span><span>                         </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; (CoercionN, TcType, CtFlavour) -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#extendFlatCache"><span class="hs-identifier hs-var">extendFlatCache</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114887"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114886"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114874"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114877"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CtFlavour
</span><a href="#local-6989586621681114873"><span class="hs-identifier hs-var">flavour</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1513"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114870"><span class="annot"><span class="annottext">role :: Role
</span><a href="#local-6989586621681114870"><span class="hs-keyword hs-var hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">EqRel -&gt; Role
</span><a href="GHC.Core.Predicate.html#eqRelRole"><span class="hs-identifier hs-var">eqRelRole</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114875"><span class="hs-identifier hs-var">eq_rel</span></a></span><span>
</span><span id="line-1514"></span><span>                             </span><span id="local-6989586621681114869"><span class="annot"><span class="annottext">xi' :: TcType
</span><a href="#local-6989586621681114869"><span class="hs-identifier hs-var hs-var">xi'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114877"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114885"><span class="hs-identifier hs-var">kind_co</span></a></span><span>
</span><span id="line-1515"></span><span>                             </span><span id="local-6989586621681114868"><span class="annot"><span class="annottext">co' :: CoercionN
</span><a href="#local-6989586621681114868"><span class="hs-identifier hs-var hs-var">co'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="#local-6989586621681114884"><span class="hs-identifier hs-var">update_co</span></a></span><span> </span><span class="annot"><span class="annottext">(CoercionN -&gt; CoercionN) -&gt; CoercionN -&gt; CoercionN
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1516"></span><span>                                   </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcCoherenceLeftCo"><span class="hs-identifier hs-var">mkTcCoherenceLeftCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114870"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114877"><span class="hs-identifier hs-var">xi</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114885"><span class="hs-identifier hs-var">kind_co</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114874"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1517"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN)))
-&gt; Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; Maybe (TcType, CoercionN)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114869"><span class="hs-identifier hs-var">xi'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114868"><span class="hs-identifier hs-var">co'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1518"></span><span>               </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1519"></span><span>
</span><span id="line-1520"></span><span>    </span><span class="annot"><a href="#local-6989586621681114928"><span class="hs-identifier hs-type">try_to_reduce_nocache</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#TyCon"><span class="hs-identifier hs-type">TyCon</span></a></span><span>   </span><span class="hs-comment">-- F, family tycon</span><span>
</span><span id="line-1521"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- args, not necessarily flattened</span><span>
</span><span id="line-1522"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1523"></span><span>    </span><span id="local-6989586621681114928"><span class="annot"><span class="annottext">try_to_reduce_nocache :: TyCon -&gt; [TcType] -&gt; FlatM (Maybe (TcType, CoercionN))
</span><a href="#local-6989586621681114928"><span class="hs-identifier hs-var hs-var">try_to_reduce_nocache</span></a></span></span><span> </span><span id="local-6989586621681114867"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114867"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span id="local-6989586621681114866"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114866"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-1524"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#checkStackDepth"><span class="hs-identifier hs-var">checkStackDepth</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114867"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114866"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1525"></span><span>           </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114865"><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="#local-6989586621681114865"><span class="hs-identifier hs-var">mb_match</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (Maybe (CoercionN, TcType))
-&gt; FlatM (Maybe (CoercionN, TcType))
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (Maybe (CoercionN, TcType))
 -&gt; FlatM (Maybe (CoercionN, TcType)))
-&gt; TcS (Maybe (CoercionN, TcType))
-&gt; FlatM (Maybe (CoercionN, TcType))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcS (Maybe (CoercionN, TcType))
</span><a href="GHC.Tc.Solver.Monad.html#matchFam"><span class="hs-identifier hs-var">matchFam</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114867"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114866"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-1526"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="#local-6989586621681114865"><span class="hs-identifier hs-var">mb_match</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1527"></span><span>                 </span><span class="hs-comment">-- NB: norm_co will always be homogeneous. All type families</span><span>
</span><span id="line-1528"></span><span>                 </span><span class="hs-comment">-- are homogeneous.</span><span>
</span><span id="line-1529"></span><span>               </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114864"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114864"><span class="hs-identifier hs-var">norm_co</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114863"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114863"><span class="hs-identifier hs-var">norm_ty</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1530"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114862"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114862"><span class="hs-identifier hs-var">xi</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114861"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114861"><span class="hs-identifier hs-var">final_co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a. FlatM a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#bumpDepth"><span class="hs-identifier hs-var">bumpDepth</span></a></span><span> </span><span class="annot"><span class="annottext">(FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN))
-&gt; FlatM (TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114863"><span class="hs-identifier hs-var">norm_ty</span></a></span><span>
</span><span id="line-1531"></span><span>                       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114860"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114860"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM EqRel
</span><a href="GHC.Tc.Solver.Flatten.html#getEqRel"><span class="hs-identifier hs-var">getEqRel</span></a></span><span>
</span><span id="line-1532"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114859"><span class="annot"><span class="annottext">co :: CoercionN
</span><a href="#local-6989586621681114859"><span class="hs-identifier hs-var hs-var">co</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#maybeTcSubCo"><span class="hs-identifier hs-var">maybeTcSubCo</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114860"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114864"><span class="hs-identifier hs-var">norm_co</span></a></span><span>
</span><span id="line-1533"></span><span>                                            </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114861"><span class="hs-identifier hs-var">final_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1534"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN)))
-&gt; Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; Maybe (TcType, CoercionN)
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114862"><span class="hs-identifier hs-var">xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114859"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1535"></span><span>               </span><span class="annot"><span class="annottext">Maybe (CoercionN, TcType)
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN) -&gt; FlatM (Maybe (TcType, CoercionN))
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TcType, CoercionN)
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1536"></span><span>
</span><span id="line-1537"></span><span class="hs-comment">{- Note [Reduce type family applications eagerly]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we come across a type-family application like (Append (Cons x Nil) t),
then, rather than flattening to a skolem etc, we may as well just reduce
it on the spot to (Cons x t).  This saves a lot of intermediate steps.
Examples that are helped are tests T9872, and T5321Fun.

Performance testing indicates that it's best to try this *twice*, once
before flattening arguments and once after flattening arguments.
Adding the extra reduction attempt before flattening arguments cut
the allocation amounts for the T9872{a,b,c} tests by half.

An example of where the early reduction appears helpful:

  type family Last x where
    Last '[x]     = x
    Last (h ': t) = Last t

  workitem: (x ~ Last '[1,2,3,4,5,6])

Flattening the argument never gets us anywhere, but trying to flatten
it at every step is quadratic in the length of the list. Reducing more
eagerly makes simplifying the right-hand type linear in its length.

Testing also indicated that the early reduction should *not* use the
flat-cache, but that the later reduction *should*. (Although the
effect was not large.)  Hence the Bool argument to try_to_reduce.  To
me (SLPJ) this seems odd; I get that eager reduction usually succeeds;
and if don't use the cache for eager reduction, we will miss most of
the opportunities for using it at all.  More exploration would be good
here.

At the end, once we've got a flat rhs, we extend the flatten-cache to record
the result. Doing so can save lots of work when the same redex shows up more
than once. Note that we record the link from the redex all the way to its
*final* value, not just the single step reduction. Interestingly, using the
flat-cache for the first reduction resulted in an increase in allocations
of about 3% for the four T9872x tests. However, using the flat-cache in
the later reduction is a similar gain. I (Richard E) don't currently (Dec '14)
have any knowledge as to *why* these facts are true.

************************************************************************
*                                                                      *
             Flattening a type variable
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-1583"></span><span>
</span><span id="line-1584"></span><span class="hs-comment">-- | The result of flattening a tyvar &quot;one step&quot;.</span><span>
</span><span id="line-1585"></span><span class="hs-keyword">data</span><span> </span><span id="FlattenTvResult"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenTvResult"><span class="hs-identifier hs-var">FlattenTvResult</span></a></span></span><span>
</span><span id="line-1586"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="FTRNotFollowed"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FTRNotFollowed"><span class="hs-identifier hs-var">FTRNotFollowed</span></a></span></span><span>
</span><span id="line-1587"></span><span>      </span><span class="hs-comment">-- ^ The inert set doesn't make the tyvar equal to anything else</span><span>
</span><span id="line-1588"></span><span>
</span><span id="line-1589"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="FTRFollowed"><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FTRFollowed"><span class="hs-identifier hs-var">FTRFollowed</span></a></span></span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span>
</span><span id="line-1590"></span><span>      </span><span class="hs-comment">-- ^ The tyvar flattens to a not-necessarily flat other type.</span><span>
</span><span id="line-1591"></span><span>      </span><span class="hs-comment">-- co :: new type ~r old type, where the role is determined by</span><span>
</span><span id="line-1592"></span><span>      </span><span class="hs-comment">-- the FlattenEnv</span><span>
</span><span id="line-1593"></span><span>
</span><span id="line-1594"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flattenTyVar"><span class="hs-identifier hs-type">flattenTyVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Xi"><span class="hs-identifier hs-type">Xi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1595"></span><span id="flattenTyVar"><span class="annot"><span class="annottext">flattenTyVar :: TcTyVar -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flattenTyVar"><span class="hs-identifier hs-var hs-var">flattenTyVar</span></a></span></span><span> </span><span id="local-6989586621681114855"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114855"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-1596"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114854"><span class="annot"><span class="annottext">FlattenTvResult
</span><a href="#local-6989586621681114854"><span class="hs-identifier hs-var">mb_yes</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; FlatM FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar1"><span class="hs-identifier hs-var">flatten_tyvar1</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114855"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1597"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">FlattenTvResult
</span><a href="#local-6989586621681114854"><span class="hs-identifier hs-var">mb_yes</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1598"></span><span>           </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FTRFollowed"><span class="hs-identifier hs-type">FTRFollowed</span></a></span><span> </span><span id="local-6989586621681114852"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114852"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span id="local-6989586621681114851"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114851"><span class="hs-identifier hs-var">co1</span></a></span></span><span>  </span><span class="hs-comment">-- Recur</span><span>
</span><span id="line-1599"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114850"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114850"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114849"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114849"><span class="hs-identifier hs-var">co2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; FlatM (TcType, CoercionN)
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_one"><span class="hs-identifier hs-var">flatten_one</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114852"><span class="hs-identifier hs-var">ty1</span></a></span><span>
</span><span id="line-1600"></span><span>                   </span><span class="hs-comment">-- ; traceFlat &quot;flattenTyVar2&quot; (ppr tv $$ ppr ty2)</span><span>
</span><span id="line-1601"></span><span>                   </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114850"><span class="hs-identifier hs-var">ty2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114849"><span class="hs-identifier hs-var">co2</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkTransCo"><span class="hs-operator hs-var">`mkTransCo`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114851"><span class="hs-identifier hs-var">co1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1602"></span><span>
</span><span id="line-1603"></span><span>           </span><span class="annot"><span class="annottext">FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#FTRNotFollowed"><span class="hs-identifier hs-var">FTRNotFollowed</span></a></span><span>   </span><span class="hs-comment">-- Done, but make sure the kind is zonked</span><span>
</span><span id="line-1604"></span><span>                            </span><span class="hs-comment">-- Note [Flattening] invariant (F0) and (F1)</span><span>
</span><span id="line-1605"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114848"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114848"><span class="hs-identifier hs-var">tv'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS TcTyVar -&gt; FlatM TcTyVar
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS TcTyVar -&gt; FlatM TcTyVar) -&gt; TcS TcTyVar -&gt; FlatM TcTyVar
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(TcType -&gt; TcS TcType) -&gt; TcTyVar -&gt; TcS TcTyVar
forall (m :: * -&gt; *).
Monad m =&gt;
(TcType -&gt; m TcType) -&gt; TcTyVar -&gt; m TcTyVar
</span><a href="GHC.Types.Var.html#updateTyVarKindM"><span class="hs-identifier hs-var">updateTyVarKindM</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114855"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1606"></span><span>                   </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114846"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114846"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1607"></span><span>                   </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114845"><span class="annot"><span class="annottext">ty' :: TcType
</span><a href="#local-6989586621681114845"><span class="hs-identifier hs-var hs-var">ty'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTy"><span class="hs-identifier hs-var">mkTyVarTy</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114848"><span class="hs-identifier hs-var">tv'</span></a></span><span>
</span><span id="line-1608"></span><span>                   </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(TcType, CoercionN) -&gt; FlatM (TcType, CoercionN)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114845"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcReflCo"><span class="hs-identifier hs-var">mkTcReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114846"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114845"><span class="hs-identifier hs-var">ty'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1609"></span><span>
</span><span id="line-1610"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar1"><span class="hs-identifier hs-type">flatten_tyvar1</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenTvResult"><span class="hs-identifier hs-type">FlattenTvResult</span></a></span><span>
</span><span id="line-1611"></span><span class="hs-comment">-- &quot;Flattening&quot; a type variable means to apply the substitution to it</span><span>
</span><span id="line-1612"></span><span class="hs-comment">-- Specifically, look up the tyvar in</span><span>
</span><span id="line-1613"></span><span class="hs-comment">--   * the internal MetaTyVar box</span><span>
</span><span id="line-1614"></span><span class="hs-comment">--   * the inerts</span><span>
</span><span id="line-1615"></span><span class="hs-comment">-- See also the documentation for FlattenTvResult</span><span>
</span><span id="line-1616"></span><span>
</span><span id="line-1617"></span><span id="flatten_tyvar1"><span class="annot"><span class="annottext">flatten_tyvar1 :: TcTyVar -&gt; FlatM FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar1"><span class="hs-identifier hs-var hs-var">flatten_tyvar1</span></a></span></span><span> </span><span id="local-6989586621681114844"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114844"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-1618"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114843"><span class="annot"><span class="annottext">Maybe TcType
</span><a href="#local-6989586621681114843"><span class="hs-identifier hs-var">mb_ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (Maybe TcType) -&gt; FlatM (Maybe TcType)
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (Maybe TcType) -&gt; FlatM (Maybe TcType))
-&gt; TcS (Maybe TcType) -&gt; FlatM (Maybe TcType)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcS (Maybe TcType)
</span><a href="GHC.Tc.Solver.Monad.html#isFilledMetaTyVar_maybe"><span class="hs-identifier hs-var">isFilledMetaTyVar_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114844"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1619"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe TcType
</span><a href="#local-6989586621681114843"><span class="hs-identifier hs-var">mb_ty</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1620"></span><span>           </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114841"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114841"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Following filled tyvar&quot;</span></span><span>
</span><span id="line-1621"></span><span>                             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114844"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#equals"><span class="hs-identifier hs-var">equals</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114841"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1622"></span><span>                         </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114839"><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114839"><span class="hs-keyword hs-var">role</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM Role
</span><a href="GHC.Tc.Solver.Flatten.html#getRole"><span class="hs-identifier hs-var">getRole</span></a></span><span>
</span><span id="line-1623"></span><span>                         </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FlattenTvResult -&gt; FlatM FlattenTvResult
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#FTRFollowed"><span class="hs-identifier hs-var">FTRFollowed</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114841"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkReflCo"><span class="hs-identifier hs-var">mkReflCo</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="#local-6989586621681114839"><span class="hs-keyword hs-var">role</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114841"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">;</span><span>
</span><span id="line-1624"></span><span>           </span><span class="annot"><span class="annottext">Maybe TcType
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unfilled tyvar&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprTyVar"><span class="hs-identifier hs-var">pprTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114844"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1625"></span><span>                         </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114838"><span class="annot"><span class="annottext">CtFlavourRole
</span><a href="#local-6989586621681114838"><span class="hs-identifier hs-var">fr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM CtFlavourRole
</span><a href="GHC.Tc.Solver.Flatten.html#getFlavourRole"><span class="hs-identifier hs-var">getFlavourRole</span></a></span><span>
</span><span id="line-1626"></span><span>                         </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; CtFlavourRole -&gt; FlatM FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar2"><span class="hs-identifier hs-var">flatten_tyvar2</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114844"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavourRole
</span><a href="#local-6989586621681114838"><span class="hs-identifier hs-var">fr</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1627"></span><span>
</span><span id="line-1628"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar2"><span class="hs-identifier hs-type">flatten_tyvar2</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtFlavourRole"><span class="hs-identifier hs-type">CtFlavourRole</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlatM"><span class="hs-identifier hs-type">FlatM</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#FlattenTvResult"><span class="hs-identifier hs-type">FlattenTvResult</span></a></span><span>
</span><span id="line-1629"></span><span class="hs-comment">-- The tyvar is not a filled-in meta-tyvar</span><span>
</span><span id="line-1630"></span><span class="hs-comment">-- Try in the inert equalities</span><span>
</span><span id="line-1631"></span><span class="hs-comment">-- See Definition [Applying a generalised substitution] in GHC.Tc.Solver.Monad</span><span>
</span><span id="line-1632"></span><span class="hs-comment">-- See Note [Stability of flattening] in GHC.Tc.Solver.Monad</span><span>
</span><span id="line-1633"></span><span>
</span><span id="line-1634"></span><span id="flatten_tyvar2"><span class="annot"><span class="annottext">flatten_tyvar2 :: TcTyVar -&gt; CtFlavourRole -&gt; FlatM FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#flatten_tyvar2"><span class="hs-identifier hs-var hs-var">flatten_tyvar2</span></a></span></span><span> </span><span id="local-6989586621681114836"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114836"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span id="local-6989586621681114835"><span class="annot"><span class="annottext">fr :: CtFlavourRole
</span><a href="#local-6989586621681114835"><span class="hs-identifier hs-var">fr</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtFlavour
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114834"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114834"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1635"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114833"><span class="annot"><span class="annottext">DTyVarEnv [Ct]
</span><a href="#local-6989586621681114833"><span class="hs-identifier hs-var">ieqs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS (DTyVarEnv [Ct]) -&gt; FlatM (DTyVarEnv [Ct])
forall a. TcS a -&gt; FlatM a
</span><a href="GHC.Tc.Solver.Flatten.html#liftTcS"><span class="hs-identifier hs-var">liftTcS</span></a></span><span> </span><span class="annot"><span class="annottext">(TcS (DTyVarEnv [Ct]) -&gt; FlatM (DTyVarEnv [Ct]))
-&gt; TcS (DTyVarEnv [Ct]) -&gt; FlatM (DTyVarEnv [Ct])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TcS (DTyVarEnv [Ct])
</span><a href="GHC.Tc.Solver.Monad.html#getInertEqs"><span class="hs-identifier hs-var">getInertEqs</span></a></span><span>
</span><span id="line-1636"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114831"><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681114831"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FlatM FlattenMode
</span><a href="GHC.Tc.Solver.Flatten.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span>
</span><span id="line-1637"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DTyVarEnv [Ct] -&gt; TcTyVar -&gt; Maybe [Ct]
forall a. DVarEnv a -&gt; TcTyVar -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupDVarEnv"><span class="hs-identifier hs-var">lookupDVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">DTyVarEnv [Ct]
</span><a href="#local-6989586621681114833"><span class="hs-identifier hs-var">ieqs</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114836"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1638"></span><span>           </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114829"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114829"><span class="hs-identifier hs-var">ct</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[Ct]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- If the first doesn't work,</span><span>
</span><span id="line-1639"></span><span>                         </span><span class="hs-comment">-- the subsequent ones won't either</span><span>
</span><span id="line-1640"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CTyEqCan"><span class="hs-identifier hs-type">CTyEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_ev :: Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114827"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114827"><span class="hs-identifier hs-var">ctev</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_tyvar :: Ct -&gt; TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_tyvar"><span class="hs-identifier hs-var">cc_tyvar</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114825"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114825"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-1641"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_rhs :: Ct -&gt; TcType
</span><a href="GHC.Tc.Types.Constraint.html#cc_rhs"><span class="hs-identifier hs-var">cc_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114823"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114823"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_eq_rel :: Ct -&gt; EqRel
</span><a href="GHC.Tc.Types.Constraint.html#cc_eq_rel"><span class="hs-identifier hs-var">cc_eq_rel</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114821"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114821"><span class="hs-identifier hs-var">ct_eq_rel</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114829"><span class="hs-identifier hs-var">ct</span></a></span><span>
</span><span id="line-1642"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114820"><span class="annot"><span class="annottext">ct_fr :: CtFlavourRole
</span><a href="#local-6989586621681114820"><span class="hs-identifier hs-var hs-var">ct_fr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; CtFlavour
</span><a href="GHC.Tc.Types.Constraint.html#ctEvFlavour"><span class="hs-identifier hs-var">ctEvFlavour</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114827"><span class="hs-identifier hs-var">ctev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114821"><span class="hs-identifier hs-var">ct_eq_rel</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1643"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CtFlavourRole
</span><a href="#local-6989586621681114820"><span class="hs-identifier hs-var">ct_fr</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavourRole -&gt; CtFlavourRole -&gt; Bool
</span><a href="GHC.Tc.Types.Constraint.html#eqCanRewriteFR"><span class="hs-operator hs-var">`eqCanRewriteFR`</span></a></span><span> </span><span class="annot"><span class="annottext">CtFlavourRole
</span><a href="#local-6989586621681114835"><span class="hs-identifier hs-var">fr</span></a></span><span>  </span><span class="hs-comment">-- This is THE key call of eqCanRewriteFR</span><span>
</span><span id="line-1644"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; FlatM ()
</span><a href="GHC.Tc.Solver.Flatten.html#traceFlat"><span class="hs-identifier hs-var">traceFlat</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Following inert tyvar&quot;</span></span><span>
</span><span id="line-1645"></span><span>                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FlattenMode -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenMode
</span><a href="#local-6989586621681114831"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-1646"></span><span>                         </span><span class="annot"><span class="annottext">TcTyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114825"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-1647"></span><span>                         </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#equals"><span class="hs-identifier hs-var">equals</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-1648"></span><span>                         </span><span class="annot"><span class="annottext">TcType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114823"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114827"><span class="hs-identifier hs-var">ctev</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1649"></span><span>                    </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114817"><span class="annot"><span class="annottext">rewrite_co1 :: CoercionN
</span><a href="#local-6989586621681114817"><span class="hs-identifier hs-var hs-var">rewrite_co1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; CtEvidence -&gt; CoercionN
CtEvidence -&gt; CoercionN
</span><a href="GHC.Tc.Types.Constraint.html#ctEvCoercion"><span class="hs-identifier hs-var">ctEvCoercion</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114827"><span class="hs-identifier hs-var">ctev</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1650"></span><span>                          </span><span id="local-6989586621681114814"><span class="annot"><span class="annottext">rewrite_co :: CoercionN
</span><a href="#local-6989586621681114814"><span class="hs-identifier hs-var hs-var">rewrite_co</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114821"><span class="hs-identifier hs-var">ct_eq_rel</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114834"><span class="hs-identifier hs-var">eq_rel</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1651"></span><span>                            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114813"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114813"><span class="hs-identifier hs-var">_rel</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">_rel</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">ReprEq</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1652"></span><span>                                    </span><span class="hs-comment">-- if this ASSERT fails, then</span><span>
</span><span id="line-1653"></span><span>                                    </span><span class="hs-comment">-- eqCanRewriteFR answered incorrectly</span><span>
</span><span id="line-1654"></span><span>                                               </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114817"><span class="hs-identifier hs-var">rewrite_co1</span></a></span><span>
</span><span id="line-1655"></span><span>                            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114817"><span class="hs-identifier hs-var">rewrite_co1</span></a></span><span>
</span><span id="line-1656"></span><span>                            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#ReprEq"><span class="hs-identifier hs-var">ReprEq</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSubCo"><span class="hs-identifier hs-var">mkSubCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114817"><span class="hs-identifier hs-var">rewrite_co1</span></a></span><span>
</span><span id="line-1657"></span><span>
</span><span id="line-1658"></span><span>                    </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">FlattenTvResult -&gt; FlatM FlattenTvResult
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#FTRFollowed"><span class="hs-identifier hs-var">FTRFollowed</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114823"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114814"><span class="hs-identifier hs-var">rewrite_co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1659"></span><span>                    </span><span class="hs-comment">-- NB: ct is Derived then fmode must be also, hence</span><span>
</span><span id="line-1660"></span><span>                    </span><span class="hs-comment">-- we are not going to touch the returned coercion</span><span>
</span><span id="line-1661"></span><span>                    </span><span class="hs-comment">-- so ctEvCoercion is fine.</span><span>
</span><span id="line-1662"></span><span>
</span><span id="line-1663"></span><span>           </span><span id="local-6989586621681114810"><span class="annot"><span class="annottext">Maybe [Ct]
</span><a href="#local-6989586621681114810"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FlattenTvResult -&gt; FlatM FlattenTvResult
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">FlattenTvResult
</span><a href="GHC.Tc.Solver.Flatten.html#FTRNotFollowed"><span class="hs-identifier hs-var">FTRNotFollowed</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1664"></span><span>
</span><span id="line-1665"></span><span class="hs-comment">{-
Note [An alternative story for the inert substitution]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(This entire note is just background, left here in case we ever want
 to return the previous state of affairs)

We used (GHC 7.8) to have this story for the inert substitution inert_eqs

 * 'a' is not in fvs(ty)
 * They are *inert* in the weaker sense that there is no infinite chain of
   (i1 `eqCanRewrite` i2), (i2 `eqCanRewrite` i3), etc

This means that flattening must be recursive, but it does allow
  [G] a ~ [b]
  [G] b ~ Maybe c

This avoids &quot;saturating&quot; the Givens, which can save a modest amount of work.
It is easy to implement, in GHC.Tc.Solver.Interact.kick_out, by only kicking out an inert
only if (a) the work item can rewrite the inert AND
        (b) the inert cannot rewrite the work item

This is significantly harder to think about. It can save a LOT of work
in occurs-check cases, but we don't care about them much.  #5837
is an example; all the constraints here are Givens

             [G] a ~ TF (a,Int)
    --&gt;
    work     TF (a,Int) ~ fsk
    inert    fsk ~ a

    ---&gt;
    work     fsk ~ (TF a, TF Int)
    inert    fsk ~ a

    ---&gt;
    work     a ~ (TF a, TF Int)
    inert    fsk ~ a

    ---&gt; (attempting to flatten (TF a) so that it does not mention a
    work     TF a ~ fsk2
    inert    a ~ (fsk2, TF Int)
    inert    fsk ~ (fsk2, TF Int)

    ---&gt; (substitute for a)
    work     TF (fsk2, TF Int) ~ fsk2
    inert    a ~ (fsk2, TF Int)
    inert    fsk ~ (fsk2, TF Int)

    ---&gt; (top-level reduction, re-orient)
    work     fsk2 ~ (TF fsk2, TF Int)
    inert    a ~ (fsk2, TF Int)
    inert    fsk ~ (fsk2, TF Int)

    ---&gt; (attempt to flatten (TF fsk2) to get rid of fsk2
    work     TF fsk2 ~ fsk3
    work     fsk2 ~ (fsk3, TF Int)
    inert    a   ~ (fsk2, TF Int)
    inert    fsk ~ (fsk2, TF Int)

    ---&gt;
    work     TF fsk2 ~ fsk3
    inert    fsk2 ~ (fsk3, TF Int)
    inert    a   ~ ((fsk3, TF Int), TF Int)
    inert    fsk ~ ((fsk3, TF Int), TF Int)

Because the incoming given rewrites all the inert givens, we get more and
more duplication in the inert set.  But this really only happens in pathological
casee, so we don't care.


************************************************************************
*                                                                      *
             Unflattening
*                                                                      *
************************************************************************

An unflattening example:
    [W] F a ~ alpha
flattens to
    [W] F a ~ fmv   (CFunEqCan)
    [W] fmv ~ alpha (CTyEqCan)
We must solve both!
-}</span><span>
</span><span id="line-1748"></span><span>
</span><span id="line-1749"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#unflattenWanteds"><span class="hs-identifier hs-type">unflattenWanteds</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span>
</span><span id="line-1750"></span><span id="unflattenWanteds"><span class="annot"><span class="annottext">unflattenWanteds :: Cts -&gt; Cts -&gt; TcS Cts
</span><a href="GHC.Tc.Solver.Flatten.html#unflattenWanteds"><span class="hs-identifier hs-var hs-var">unflattenWanteds</span></a></span></span><span> </span><span id="local-6989586621681114809"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114809"><span class="hs-identifier hs-var">tv_eqs</span></a></span></span><span> </span><span id="local-6989586621681114808"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114808"><span class="hs-identifier hs-var">funeqs</span></a></span></span><span>
</span><span id="line-1751"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114807"><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114807"><span class="hs-identifier hs-var">tclvl</span></a></span></span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcS TcLevel
</span><a href="GHC.Tc.Solver.Monad.html#getTcLevel"><span class="hs-identifier hs-var">getTcLevel</span></a></span><span>
</span><span id="line-1752"></span><span>
</span><span id="line-1753"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unflattening&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcS ()) -&gt; SDoc -&gt; TcS ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1754"></span><span>        </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Funeqs =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114808"><span class="hs-identifier hs-var">funeqs</span></a></span><span>
</span><span id="line-1755"></span><span>             </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Tv eqs =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114809"><span class="hs-identifier hs-var">tv_eqs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-1756"></span><span>
</span><span id="line-1757"></span><span>         </span><span class="hs-comment">-- Step 1: unflatten the CFunEqCans, except if that causes an occurs check</span><span>
</span><span id="line-1758"></span><span>         </span><span class="hs-comment">-- Occurs check: consider  [W] alpha ~ [F alpha]</span><span>
</span><span id="line-1759"></span><span>         </span><span class="hs-comment">--                 ==&gt; (flatten) [W] F alpha ~ fmv, [W] alpha ~ [fmv]</span><span>
</span><span id="line-1760"></span><span>         </span><span class="hs-comment">--                 ==&gt; (unify)   [W] F [fmv] ~ fmv</span><span>
</span><span id="line-1761"></span><span>         </span><span class="hs-comment">-- See Note [Unflatten using funeqs first]</span><span>
</span><span id="line-1762"></span><span>      </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114803"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114803"><span class="hs-identifier hs-var">funeqs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; Cts -&gt; TcS Cts) -&gt; Cts -&gt; Cts -&gt; TcS Cts
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; b -&gt; m b) -&gt; b -&gt; t a -&gt; m b
</span><a href="../../base/src/Data.Foldable.html#foldrM"><span class="hs-identifier hs-var">foldrM</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114802"><span class="hs-identifier hs-var">unflatten_funeq</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="GHC.Tc.Types.Constraint.html#emptyCts"><span class="hs-identifier hs-var">emptyCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114808"><span class="hs-identifier hs-var">funeqs</span></a></span><span>
</span><span id="line-1763"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unflattening 1&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcS ()) -&gt; SDoc -&gt; TcS ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114803"><span class="hs-identifier hs-var">funeqs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1764"></span><span>
</span><span id="line-1765"></span><span>          </span><span class="hs-comment">-- Step 2: unify the tv_eqs, if possible</span><span>
</span><span id="line-1766"></span><span>      </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114800"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114800"><span class="hs-identifier hs-var">tv_eqs</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; Cts -&gt; TcS Cts) -&gt; Cts -&gt; Cts -&gt; TcS Cts
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; b -&gt; m b) -&gt; b -&gt; t a -&gt; m b
</span><a href="../../base/src/Data.Foldable.html#foldrM"><span class="hs-identifier hs-var">foldrM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcLevel -&gt; Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114799"><span class="hs-identifier hs-var">unflatten_eq</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114807"><span class="hs-identifier hs-var">tclvl</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="GHC.Tc.Types.Constraint.html#emptyCts"><span class="hs-identifier hs-var">emptyCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114809"><span class="hs-identifier hs-var">tv_eqs</span></a></span><span>
</span><span id="line-1767"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unflattening 2&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcS ()) -&gt; SDoc -&gt; TcS ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114800"><span class="hs-identifier hs-var">tv_eqs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1768"></span><span>
</span><span id="line-1769"></span><span>          </span><span class="hs-comment">-- Step 3: fill any remaining fmvs with fresh unification variables</span><span>
</span><span id="line-1770"></span><span>      </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114798"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114798"><span class="hs-identifier hs-var">funeqs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; TcS Ct) -&gt; Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a b.
Monad m =&gt;
(a -&gt; m b) -&gt; Bag a -&gt; m (Bag b)
</span><a href="GHC.Data.Bag.html#mapBagM"><span class="hs-identifier hs-var">mapBagM</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; TcS Ct
</span><a href="#local-6989586621681114796"><span class="hs-identifier hs-var">finalise_funeq</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114803"><span class="hs-identifier hs-var">funeqs</span></a></span><span>
</span><span id="line-1771"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unflattening 3&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcS ()) -&gt; SDoc -&gt; TcS ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114798"><span class="hs-identifier hs-var">funeqs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1772"></span><span>
</span><span id="line-1773"></span><span>          </span><span class="hs-comment">-- Step 4: remove any tv_eqs that look like ty ~ ty</span><span>
</span><span id="line-1774"></span><span>      </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114795"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114795"><span class="hs-identifier hs-var">tv_eqs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; Cts -&gt; TcS Cts) -&gt; Cts -&gt; Cts -&gt; TcS Cts
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; b -&gt; m b) -&gt; b -&gt; t a -&gt; m b
</span><a href="../../base/src/Data.Foldable.html#foldrM"><span class="hs-identifier hs-var">foldrM</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114794"><span class="hs-identifier hs-var">finalise_eq</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="GHC.Tc.Types.Constraint.html#emptyCts"><span class="hs-identifier hs-var">emptyCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114800"><span class="hs-identifier hs-var">tv_eqs</span></a></span><span>
</span><span id="line-1775"></span><span>
</span><span id="line-1776"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681114793"><span class="annot"><span class="annottext">all_flat :: Cts
</span><a href="#local-6989586621681114793"><span class="hs-identifier hs-var hs-var">all_flat</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114795"><span class="hs-identifier hs-var">tv_eqs</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#andCts"><span class="hs-operator hs-var">`andCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114798"><span class="hs-identifier hs-var">funeqs</span></a></span><span>
</span><span id="line-1777"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Unflattening done&quot;</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; TcS ()) -&gt; SDoc -&gt; TcS ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts -&gt; SDoc
</span><a href="GHC.Tc.Types.Constraint.html#pprCts"><span class="hs-identifier hs-var">pprCts</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114793"><span class="hs-identifier hs-var">all_flat</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1778"></span><span>
</span><span id="line-1779"></span><span>      </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114793"><span class="hs-identifier hs-var">all_flat</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1780"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1781"></span><span>    </span><span class="hs-comment">----------------</span><span>
</span><span id="line-1782"></span><span>    </span><span class="annot"><a href="#local-6989586621681114802"><span class="hs-identifier hs-type">unflatten_funeq</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span>
</span><span id="line-1783"></span><span>    </span><span id="local-6989586621681114802"><span class="annot"><span class="annottext">unflatten_funeq :: Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114802"><span class="hs-identifier hs-var hs-var">unflatten_funeq</span></a></span></span><span> </span><span id="local-6989586621681114791"><span class="annot"><span class="annottext">ct :: Ct
</span><a href="#local-6989586621681114791"><span class="hs-identifier hs-var">ct</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CFunEqCan"><span class="hs-identifier hs-type">CFunEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_fun :: Ct -&gt; TyCon
</span><a href="GHC.Tc.Types.Constraint.html#cc_fun"><span class="hs-identifier hs-var">cc_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114790"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114790"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_tyargs :: Ct -&gt; [TcType]
</span><a href="GHC.Tc.Types.Constraint.html#cc_tyargs"><span class="hs-identifier hs-var">cc_tyargs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114789"><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114789"><span class="hs-identifier hs-var">xis</span></a></span></span><span>
</span><span id="line-1784"></span><span>                                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_fsk :: Ct -&gt; TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_fsk"><span class="hs-identifier hs-var">cc_fsk</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114788"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114788"><span class="hs-identifier hs-var">fmv</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_ev :: Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114787"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114787"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621681114786"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114786"><span class="hs-identifier hs-var">rest</span></a></span></span><span>
</span><span id="line-1785"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>   </span><span class="hs-comment">-- fmv should be an un-filled flatten meta-tv;</span><span>
</span><span id="line-1786"></span><span>               </span><span class="hs-comment">-- we now fix its final value by filling it, being careful</span><span>
</span><span id="line-1787"></span><span>               </span><span class="hs-comment">-- to observe the occurs check.  Zonking will eliminate it</span><span>
</span><span id="line-1788"></span><span>               </span><span class="hs-comment">-- altogether in due course</span><span>
</span><span id="line-1789"></span><span>             </span><span id="local-6989586621681114785"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114785"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; [TcType] -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681114790"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[TcType]
</span><a href="#local-6989586621681114789"><span class="hs-identifier hs-var">xis</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1790"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; TcType -&gt; Maybe TcType
</span><a href="GHC.Core.Type.html#occCheckExpand"><span class="hs-identifier hs-var">occCheckExpand</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114788"><span class="hs-identifier hs-var">fmv</span></a></span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114785"><span class="hs-identifier hs-var">rhs'</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1791"></span><span>               </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114783"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114783"><span class="hs-identifier hs-var">rhs''</span></a></span></span><span>    </span><span class="hs-comment">-- Normal case: fill the tyvar</span><span>
</span><span id="line-1792"></span><span>                 </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; EqRel -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Flatten.html#setReflEvidence"><span class="hs-identifier hs-var">setReflEvidence</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114787"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114783"><span class="hs-identifier hs-var">rhs''</span></a></span><span>
</span><span id="line-1793"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#unflattenFmv"><span class="hs-identifier hs-var">unflattenFmv</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114788"><span class="hs-identifier hs-var">fmv</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114783"><span class="hs-identifier hs-var">rhs''</span></a></span><span>
</span><span id="line-1794"></span><span>                       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114786"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1795"></span><span>
</span><span id="line-1796"></span><span>               </span><span class="annot"><span class="annottext">Maybe TcType
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>  </span><span class="hs-comment">-- Occurs check</span><span>
</span><span id="line-1797"></span><span>                          </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114791"><span class="hs-identifier hs-var">ct</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#consCts"><span class="hs-operator hs-var">`consCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114786"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1798"></span><span>
</span><span id="line-1799"></span><span>    </span><span class="annot"><a href="#local-6989586621681114802"><span class="hs-identifier hs-var">unflatten_funeq</span></a></span><span> </span><span id="local-6989586621681114779"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114779"><span class="hs-identifier hs-var">other_ct</span></a></span></span><span> </span><span class="annot"><span class="annottext">Cts
</span><span class="hs-identifier">_</span></span><span>
</span><span id="line-1800"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS Cts
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;unflatten_funeq&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114779"><span class="hs-identifier hs-var">other_ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1801"></span><span>
</span><span id="line-1802"></span><span>    </span><span class="hs-comment">----------------</span><span>
</span><span id="line-1803"></span><span>    </span><span class="annot"><a href="#local-6989586621681114796"><span class="hs-identifier hs-type">finalise_funeq</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span>
</span><span id="line-1804"></span><span>    </span><span id="local-6989586621681114796"><span class="annot"><span class="annottext">finalise_funeq :: Ct -&gt; TcS Ct
</span><a href="#local-6989586621681114796"><span class="hs-identifier hs-var hs-var">finalise_funeq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CFunEqCan"><span class="hs-identifier hs-type">CFunEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_fsk :: Ct -&gt; TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_fsk"><span class="hs-identifier hs-var">cc_fsk</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114778"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114778"><span class="hs-identifier hs-var">fmv</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_ev :: Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114777"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114777"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1805"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#demoteUnfilledFmv"><span class="hs-identifier hs-var">demoteUnfilledFmv</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114778"><span class="hs-identifier hs-var">fmv</span></a></span><span>
</span><span id="line-1806"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Ct -&gt; TcS Ct
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; Ct
</span><a href="GHC.Tc.Types.Constraint.html#mkNonCanonical"><span class="hs-identifier hs-var">mkNonCanonical</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114777"><span class="hs-identifier hs-var">ev</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1807"></span><span>    </span><span class="annot"><a href="#local-6989586621681114796"><span class="hs-identifier hs-var">finalise_funeq</span></a></span><span> </span><span id="local-6989586621681114774"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114774"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS Ct
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;finalise_funeq&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114774"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1808"></span><span>
</span><span id="line-1809"></span><span>    </span><span class="hs-comment">----------------</span><span>
</span><span id="line-1810"></span><span>    </span><span class="annot"><a href="#local-6989586621681114799"><span class="hs-identifier hs-type">unflatten_eq</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcLevel"><span class="hs-identifier hs-type">TcLevel</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span>
</span><span id="line-1811"></span><span>    </span><span id="local-6989586621681114799"><span class="annot"><span class="annottext">unflatten_eq :: TcLevel -&gt; Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114799"><span class="hs-identifier hs-var hs-var">unflatten_eq</span></a></span></span><span> </span><span id="local-6989586621681114773"><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114773"><span class="hs-identifier hs-var">tclvl</span></a></span></span><span> </span><span id="local-6989586621681114772"><span class="annot"><span class="annottext">ct :: Ct
</span><a href="#local-6989586621681114772"><span class="hs-identifier hs-var">ct</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CTyEqCan"><span class="hs-identifier hs-type">CTyEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_ev :: Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114771"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114771"><span class="hs-identifier hs-var">ev</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_tyvar :: Ct -&gt; TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_tyvar"><span class="hs-identifier hs-var">cc_tyvar</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114770"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-1812"></span><span>                                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_rhs :: Ct -&gt; TcType
</span><a href="GHC.Tc.Types.Constraint.html#cc_rhs"><span class="hs-identifier hs-var">cc_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114769"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114769"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_eq_rel :: Ct -&gt; EqRel
</span><a href="GHC.Tc.Types.Constraint.html#cc_eq_rel"><span class="hs-identifier hs-var">cc_eq_rel</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114768"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114768"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621681114767"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114767"><span class="hs-identifier hs-var">rest</span></a></span></span><span>
</span><span id="line-1813"></span><span>
</span><span id="line-1814"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114768"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-comment">-- See Note [Do not unify representational equalities]</span><span>
</span><span id="line-1815"></span><span>                        </span><span class="hs-comment">--     in GHC.Tc.Solver.Interact</span><span>
</span><span id="line-1816"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isFmvTyVar"><span class="hs-identifier hs-var">isFmvTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span><span>   </span><span class="hs-comment">-- Previously these fmvs were untouchable,</span><span>
</span><span id="line-1817"></span><span>                        </span><span class="hs-comment">-- but now they are touchable</span><span>
</span><span id="line-1818"></span><span>                        </span><span class="hs-comment">-- NB: unlike unflattenFmv, filling a fmv here /does/</span><span>
</span><span id="line-1819"></span><span>                        </span><span class="hs-comment">--     bump the unification count; it is &quot;improvement&quot;</span><span>
</span><span id="line-1820"></span><span>                        </span><span class="hs-comment">-- Note [Unflattening can force the solver to iterate]</span><span>
</span><span id="line-1821"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">tyVarKind</span><span> </span><span class="hs-identifier">tv</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">eqType</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">tcTypeKind</span><span> </span><span class="hs-identifier">rhs</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">ct</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1822"></span><span>           </span><span class="hs-comment">-- CTyEqCan invariant (TyEq:K) should ensure this is true</span><span>
</span><span id="line-1823"></span><span>        </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114763"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114763"><span class="hs-identifier hs-var">is_filled</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcS Bool
</span><a href="GHC.Tc.Solver.Monad.html#isFilledMetaTyVar"><span class="hs-identifier hs-var">isFilledMetaTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1824"></span><span>           </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114761"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114761"><span class="hs-identifier hs-var">elim</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114763"><span class="hs-identifier hs-var">is_filled</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1825"></span><span>               </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;unflatten_eq 2&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114772"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1826"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; TcTyVar -&gt; TcType -&gt; TcS Bool
</span><a href="GHC.Tc.Solver.Flatten.html#tryFill"><span class="hs-identifier hs-var">tryFill</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114771"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114769"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1827"></span><span>               </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#traceTcS"><span class="hs-identifier hs-var">traceTcS</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;unflatten_eq 3&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114772"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1828"></span><span>                           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; TcLevel -&gt; TcTyVar -&gt; TcType -&gt; TcS Bool
</span><a href="#local-6989586621681114759"><span class="hs-identifier hs-var">try_fill_rhs</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114771"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114773"><span class="hs-identifier hs-var">tclvl</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114769"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1829"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114761"><span class="hs-identifier hs-var">elim</span></a></span><span>
</span><span id="line-1830"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; EqRel -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Flatten.html#setReflEvidence"><span class="hs-identifier hs-var">setReflEvidence</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114771"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114768"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTy"><span class="hs-identifier hs-var">mkTyVarTy</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114770"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1831"></span><span>                     </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114767"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1832"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114772"><span class="hs-identifier hs-var">ct</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#consCts"><span class="hs-operator hs-var">`consCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114767"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1833"></span><span>
</span><span id="line-1834"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1835"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114772"><span class="hs-identifier hs-var">ct</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#consCts"><span class="hs-operator hs-var">`consCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114767"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1836"></span><span>
</span><span id="line-1837"></span><span>    </span><span class="annot"><a href="#local-6989586621681114799"><span class="hs-identifier hs-var">unflatten_eq</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681114758"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114758"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="annot"><span class="annottext">Cts
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS Cts
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;unflatten_irred&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114758"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1838"></span><span>
</span><span id="line-1839"></span><span>    </span><span class="hs-comment">----------------</span><span>
</span><span id="line-1840"></span><span>    </span><span id="local-6989586621681114759"><span class="annot"><span class="annottext">try_fill_rhs :: CtEvidence -&gt; TcLevel -&gt; TcTyVar -&gt; TcType -&gt; TcS Bool
</span><a href="#local-6989586621681114759"><span class="hs-identifier hs-var hs-var">try_fill_rhs</span></a></span></span><span> </span><span id="local-6989586621681114754"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114754"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span id="local-6989586621681114753"><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114753"><span class="hs-identifier hs-var">tclvl</span></a></span></span><span> </span><span id="local-6989586621681114752"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114752"><span class="hs-identifier hs-var">lhs_tv</span></a></span></span><span> </span><span id="local-6989586621681114751"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114751"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1841"></span><span>         </span><span class="hs-comment">-- Constraint is lhs_tv ~ rhs_tv,</span><span>
</span><span id="line-1842"></span><span>         </span><span class="hs-comment">-- and lhs_tv is filled, so try RHS</span><span>
</span><span id="line-1843"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114750"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114749"><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114749"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Maybe (TcTyVar, CoercionN)
</span><a href="GHC.Core.Type.html#getCastedTyVar_maybe"><span class="hs-identifier hs-var">getCastedTyVar_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114751"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1844"></span><span>                             </span><span class="hs-comment">-- co :: kind(rhs_tv) ~ kind(lhs_tv)</span><span>
</span><span id="line-1845"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isFmvTyVar"><span class="hs-identifier hs-var">isFmvTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcLevel -&gt; TcTyVar -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isTouchableMetaTyVar"><span class="hs-identifier hs-var">isTouchableMetaTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681114753"><span class="hs-identifier hs-var">tclvl</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span><span>
</span><span id="line-1846"></span><span>                              </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isTyVarTyVar"><span class="hs-identifier hs-var">isTyVarTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1847"></span><span>                              </span><span class="hs-comment">-- LHS is a filled fmv, and so is a type</span><span>
</span><span id="line-1848"></span><span>                              </span><span class="hs-comment">-- family application, which a TyVarTv should</span><span>
</span><span id="line-1849"></span><span>                              </span><span class="hs-comment">-- not unify with</span><span>
</span><span id="line-1850"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114745"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114745"><span class="hs-identifier hs-var">is_filled</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcS Bool
</span><a href="GHC.Tc.Solver.Monad.html#isFilledMetaTyVar"><span class="hs-identifier hs-var">isFilledMetaTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span><span>
</span><span id="line-1851"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114745"><span class="hs-identifier hs-var">is_filled</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcS Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1852"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; TcTyVar -&gt; TcType -&gt; TcS Bool
</span><a href="GHC.Tc.Solver.Flatten.html#tryFill"><span class="hs-identifier hs-var">tryFill</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114754"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114750"><span class="hs-identifier hs-var">rhs_tv</span></a></span><span>
</span><span id="line-1853"></span><span>                          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTy"><span class="hs-identifier hs-var">mkTyVarTy</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114752"><span class="hs-identifier hs-var">lhs_tv</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; CoercionN -&gt; TcType
</span><a href="GHC.Core.Type.html#mkCastTy"><span class="hs-operator hs-var">`mkCastTy`</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN -&gt; CoercionN
</span><a href="GHC.Core.Coercion.html#mkSymCo"><span class="hs-identifier hs-var">mkSymCo</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114749"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1854"></span><span>
</span><span id="line-1855"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1856"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcS Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1857"></span><span>
</span><span id="line-1858"></span><span>    </span><span class="hs-comment">----------------</span><span>
</span><span id="line-1859"></span><span>    </span><span class="annot"><a href="#local-6989586621681114794"><span class="hs-identifier hs-type">finalise_eq</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span>
</span><span id="line-1860"></span><span>    </span><span id="local-6989586621681114794"><span class="annot"><span class="annottext">finalise_eq :: Ct -&gt; Cts -&gt; TcS Cts
</span><a href="#local-6989586621681114794"><span class="hs-identifier hs-var hs-var">finalise_eq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CTyEqCan"><span class="hs-identifier hs-type">CTyEqCan</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">cc_ev :: Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#cc_ev"><span class="hs-identifier hs-var">cc_ev</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114744"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114744"><span class="hs-identifier hs-var">ev</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_tyvar :: Ct -&gt; TcTyVar
</span><a href="GHC.Tc.Types.Constraint.html#cc_tyvar"><span class="hs-identifier hs-var">cc_tyvar</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114743"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114743"><span class="hs-identifier hs-var">tv</span></a></span></span><span>
</span><span id="line-1861"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_rhs :: Ct -&gt; TcType
</span><a href="GHC.Tc.Types.Constraint.html#cc_rhs"><span class="hs-identifier hs-var">cc_rhs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114742"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114742"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">cc_eq_rel :: Ct -&gt; EqRel
</span><a href="GHC.Tc.Types.Constraint.html#cc_eq_rel"><span class="hs-identifier hs-var">cc_eq_rel</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114741"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114741"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621681114740"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114740"><span class="hs-identifier hs-var">rest</span></a></span></span><span>
</span><span id="line-1862"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isFmvTyVar"><span class="hs-identifier hs-var">isFmvTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114743"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1863"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114739"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114739"><span class="hs-identifier hs-var">ty1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcTyVar"><span class="hs-identifier hs-var">zonkTcTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114743"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-1864"></span><span>           </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681114737"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114737"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114742"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1865"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114739"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; TcType -&gt; TcType -&gt; Bool
TcType -&gt; TcType -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#tcEqType"><span class="hs-operator hs-var">`tcEqType`</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114737"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1866"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; EqRel -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Flatten.html#setReflEvidence"><span class="hs-identifier hs-var">setReflEvidence</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114744"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114741"><span class="hs-identifier hs-var">eq_rel</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114737"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1867"></span><span>                     </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114740"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1868"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; Ct
</span><a href="GHC.Tc.Types.Constraint.html#mkNonCanonical"><span class="hs-identifier hs-var">mkNonCanonical</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114744"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#consCts"><span class="hs-operator hs-var">`consCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114740"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1869"></span><span>
</span><span id="line-1870"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1871"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Cts -&gt; TcS Cts
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CtEvidence -&gt; Ct
</span><a href="GHC.Tc.Types.Constraint.html#mkNonCanonical"><span class="hs-identifier hs-var">mkNonCanonical</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114744"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#consCts"><span class="hs-operator hs-var">`consCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681114740"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1872"></span><span>
</span><span id="line-1873"></span><span>    </span><span class="annot"><a href="#local-6989586621681114794"><span class="hs-identifier hs-var">finalise_eq</span></a></span><span> </span><span id="local-6989586621681114735"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114735"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="annot"><span class="annottext">Cts
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; TcS Cts
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;finalise_irred&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681114735"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1874"></span><span>
</span><span id="line-1875"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#tryFill"><span class="hs-identifier hs-type">tryFill</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtEvidence"><span class="hs-identifier hs-type">CtEvidence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1876"></span><span class="hs-comment">-- (tryFill tv rhs ev) assumes 'tv' is an /un-filled/ MetaTv</span><span>
</span><span id="line-1877"></span><span class="hs-comment">-- If tv does not appear in 'rhs', it set tv := rhs,</span><span>
</span><span id="line-1878"></span><span class="hs-comment">-- binds the evidence (which should be a CtWanted) to Refl&lt;rhs&gt;</span><span>
</span><span id="line-1879"></span><span class="hs-comment">-- and return True.  Otherwise returns False</span><span>
</span><span id="line-1880"></span><span id="tryFill"><span class="annot"><span class="annottext">tryFill :: CtEvidence -&gt; TcTyVar -&gt; TcType -&gt; TcS Bool
</span><a href="GHC.Tc.Solver.Flatten.html#tryFill"><span class="hs-identifier hs-var hs-var">tryFill</span></a></span></span><span> </span><span id="local-6989586621681114734"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114734"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span id="local-6989586621681114733"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114733"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span id="local-6989586621681114732"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114732"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1881"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">isGiven</span><span> </span><span class="hs-identifier">ev</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">ev</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1882"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681114730"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114730"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcS TcType
</span><a href="GHC.Tc.Solver.Monad.html#zonkTcType"><span class="hs-identifier hs-var">zonkTcType</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114732"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1883"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1884"></span><span>            </span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114729"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114729"><span class="hs-identifier hs-var">tv'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Maybe TcTyVar
</span><a href="GHC.Tc.Utils.TcType.html#tcGetTyVar_maybe"><span class="hs-identifier hs-var">tcGetTyVar_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114730"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1885"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114733"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcTyVar -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114729"><span class="hs-identifier hs-var">tv'</span></a></span><span>   </span><span class="hs-comment">-- tv == rhs</span><span>
</span><span id="line-1886"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcS Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1887"></span><span>
</span><span id="line-1888"></span><span>            </span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114727"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114727"><span class="hs-identifier hs-var">rhs''</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; TcType -&gt; Maybe TcType
</span><a href="GHC.Core.Type.html#occCheckExpand"><span class="hs-identifier hs-var">occCheckExpand</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114733"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114730"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1889"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>       </span><span class="hs-comment">-- Fill the tyvar</span><span>
</span><span id="line-1890"></span><span>                      </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#unifyTyVar"><span class="hs-identifier hs-var">unifyTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114733"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114727"><span class="hs-identifier hs-var">rhs''</span></a></span><span>
</span><span id="line-1891"></span><span>                    </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcS Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1892"></span><span>
</span><span id="line-1893"></span><span>            </span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-comment">-- Occurs check</span><span>
</span><span id="line-1894"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; TcS Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1895"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-1896"></span><span>
</span><span id="line-1897"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#setReflEvidence"><span class="hs-identifier hs-type">setReflEvidence</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtEvidence"><span class="hs-identifier hs-type">CtEvidence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html#EqRel"><span class="hs-identifier hs-type">EqRel</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Monad.html#TcS"><span class="hs-identifier hs-type">TcS</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1898"></span><span id="setReflEvidence"><span class="annot"><span class="annottext">setReflEvidence :: CtEvidence -&gt; EqRel -&gt; TcType -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Flatten.html#setReflEvidence"><span class="hs-identifier hs-var hs-var">setReflEvidence</span></a></span></span><span> </span><span id="local-6989586621681114725"><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114725"><span class="hs-identifier hs-var">ev</span></a></span></span><span> </span><span id="local-6989586621681114724"><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114724"><span class="hs-identifier hs-var">eq_rel</span></a></span></span><span> </span><span id="local-6989586621681114723"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114723"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1899"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CtEvidence -&gt; EvTerm -&gt; TcS ()
</span><a href="GHC.Tc.Solver.Monad.html#setEvBindIfWanted"><span class="hs-identifier hs-var">setEvBindIfWanted</span></a></span><span> </span><span class="annot"><span class="annottext">CtEvidence
</span><a href="#local-6989586621681114725"><span class="hs-identifier hs-var">ev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoercionN -&gt; EvTerm
</span><a href="GHC.Tc.Types.Evidence.html#evCoercion"><span class="hs-identifier hs-var">evCoercion</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionN
</span><a href="#local-6989586621681114720"><span class="hs-identifier hs-var">refl_co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1900"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1901"></span><span>    </span><span id="local-6989586621681114720"><span class="annot"><span class="annottext">refl_co :: CoercionN
</span><a href="#local-6989586621681114720"><span class="hs-identifier hs-var hs-var">refl_co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Role -&gt; TcType -&gt; CoercionN
</span><a href="GHC.Tc.Types.Evidence.html#mkTcReflCo"><span class="hs-identifier hs-var">mkTcReflCo</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">EqRel -&gt; Role
</span><a href="GHC.Core.Predicate.html#eqRelRole"><span class="hs-identifier hs-var">eqRelRole</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="#local-6989586621681114724"><span class="hs-identifier hs-var">eq_rel</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114723"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1902"></span><span>
</span><span id="line-1903"></span><span class="hs-comment">{-
Note [Unflatten using funeqs first]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [W] G a ~ Int
    [W] F (G a) ~ G a

do not want to end up with
    [W] F Int ~ Int
because that might actually hold!  Better to end up with the two above
unsolved constraints.  The flat form will be

    G a ~ fmv1     (CFunEqCan)
    F fmv1 ~ fmv2  (CFunEqCan)
    fmv1 ~ Int     (CTyEqCan)
    fmv1 ~ fmv2    (CTyEqCan)

Flatten using the fun-eqs first.
-}</span><span>
</span><span id="line-1921"></span><span>
</span><span id="line-1922"></span><span class="hs-comment">-- | Like 'splitPiTys'' but comes with a 'Bool' which is 'True' iff there is at</span><span>
</span><span id="line-1923"></span><span class="hs-comment">-- least one named binder.</span><span>
</span><span id="line-1924"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#split_pi_tys%27"><span class="hs-identifier hs-type">split_pi_tys'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span>
</span><span id="line-1925"></span><span id="split_pi_tys%27"><span class="annot"><span class="annottext">split_pi_tys' :: TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="GHC.Tc.Solver.Flatten.html#split_pi_tys%27"><span class="hs-identifier hs-var hs-var">split_pi_tys'</span></a></span></span><span> </span><span id="local-6989586621681114719"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114719"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114719"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114719"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-1926"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1927"></span><span>     </span><span class="hs-comment">-- put common cases first</span><span>
</span><span id="line-1928"></span><span>  </span><span id="local-6989586621681114718"><span class="annot"><span class="annottext">split :: TcType -&gt; TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="#local-6989586621681114718"><span class="hs-identifier hs-var hs-var">split</span></a></span></span><span> </span><span class="annot"><span class="annottext">TcType
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#ForAllTy"><span class="hs-identifier hs-type">ForAllTy</span></a></span><span> </span><span id="local-6989586621681114717"><span class="annot"><span class="annottext">TyVarBinder
</span><a href="#local-6989586621681114717"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621681114716"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114716"><span class="hs-identifier hs-var">res</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114715"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114715"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114714"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114714"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114716"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114716"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-1929"></span><span>                                   </span><span class="hs-keyword">in</span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarBinder -&gt; TyCoBinder
</span><a href="GHC.Core.TyCo.Rep.html#Named"><span class="hs-identifier hs-var">Named</span></a></span><span> </span><span class="annot"><span class="annottext">TyVarBinder
</span><a href="#local-6989586621681114717"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">TyCoBinder -&gt; [TyCoBinder] -&gt; [TyCoBinder]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114715"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114714"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span>
</span><span id="line-1930"></span><span>  </span><span class="annot"><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#FunTy"><span class="hs-identifier hs-type">FunTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ft_af :: TcType -&gt; AnonArgFlag
</span><a href="GHC.Core.TyCo.Rep.html#ft_af"><span class="hs-identifier hs-var">ft_af</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114711"><span class="annot"><span class="annottext">AnonArgFlag
</span><a href="#local-6989586621681114711"><span class="hs-identifier hs-var">af</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_mult :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_mult"><span class="hs-identifier hs-var">ft_mult</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114710"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114710"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_arg :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_arg"><span class="hs-identifier hs-var">ft_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114709"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114709"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ft_res :: TcType -&gt; TcType
</span><a href="GHC.Core.TyCo.Rep.html#ft_res"><span class="hs-identifier hs-var">ft_res</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681114708"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114708"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1931"></span><span>                                 </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114707"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114707"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114706"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114706"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114705"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114705"><span class="hs-identifier hs-var">named</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114708"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114708"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-1932"></span><span>                                   </span><span class="hs-keyword">in</span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnonArgFlag -&gt; Scaled TcType -&gt; TyCoBinder
</span><a href="GHC.Core.TyCo.Rep.html#Anon"><span class="hs-identifier hs-var">Anon</span></a></span><span> </span><span class="annot"><span class="annottext">AnonArgFlag
</span><a href="#local-6989586621681114711"><span class="hs-identifier hs-var">af</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; Scaled TcType
forall a. TcType -&gt; a -&gt; Scaled a
</span><a href="GHC.Core.Type.html#mkScaled"><span class="hs-identifier hs-var">mkScaled</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114710"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114709"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TyCoBinder -&gt; [TyCoBinder] -&gt; [TyCoBinder]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114707"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114706"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114705"><span class="hs-identifier hs-var">named</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1933"></span><span>
</span><span id="line-1934"></span><span>  </span><span class="annot"><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span id="local-6989586621681114702"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114702"><span class="hs-identifier hs-var">orig_ty</span></a></span></span><span> </span><span id="local-6989586621681114701"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114701"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681114700"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114700"><span class="hs-identifier hs-var">ty'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Maybe TcType
</span><a href="GHC.Core.Type.html#coreView"><span class="hs-identifier hs-var">coreView</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114701"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; ([TyCoBinder], TcType, Bool)
</span><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114702"><span class="hs-identifier hs-var">orig_ty</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114700"><span class="hs-identifier hs-var">ty'</span></a></span><span>
</span><span id="line-1935"></span><span>  </span><span class="annot"><a href="#local-6989586621681114718"><span class="hs-identifier hs-var">split</span></a></span><span> </span><span id="local-6989586621681114698"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114698"><span class="hs-identifier hs-var">orig_ty</span></a></span></span><span> </span><span class="annot"><span class="annottext">TcType
</span><span class="hs-identifier">_</span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681114698"><span class="hs-identifier hs-var">orig_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span>
</span><span id="line-1936"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#split_pi_tys%27"><span class="hs-pragma hs-type">split_pi_tys'</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1937"></span><span>
</span><span id="line-1938"></span><span class="hs-comment">-- | Like 'tyConBindersTyCoBinders' but you also get a 'Bool' which is true iff</span><span>
</span><span id="line-1939"></span><span class="hs-comment">-- there is at least one named binder.</span><span>
</span><span id="line-1940"></span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#ty_con_binders_ty_binders%27"><span class="hs-identifier hs-type">ty_con_binders_ty_binders'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCon.html#TyConBinder"><span class="hs-identifier hs-type">TyConBinder</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#TyCoBinder"><span class="hs-identifier hs-type">TyCoBinder</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span>
</span><span id="line-1941"></span><span id="ty_con_binders_ty_binders%27"><span class="annot"><span class="annottext">ty_con_binders_ty_binders' :: [TyConBinder] -&gt; ([TyCoBinder], Bool)
</span><a href="GHC.Tc.Solver.Flatten.html#ty_con_binders_ty_binders%27"><span class="hs-identifier hs-var hs-var">ty_con_binders_ty_binders'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyConBinder -&gt; ([TyCoBinder], Bool) -&gt; ([TyCoBinder], Bool))
-&gt; ([TyCoBinder], Bool) -&gt; [TyConBinder] -&gt; ([TyCoBinder], Bool)
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">TyConBinder -&gt; ([TyCoBinder], Bool) -&gt; ([TyCoBinder], Bool)
</span><a href="#local-6989586621681114696"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span>
</span><span id="line-1942"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1943"></span><span>    </span><span id="local-6989586621681114696"><span class="annot"><span class="annottext">go :: TyConBinder -&gt; ([TyCoBinder], Bool) -&gt; ([TyCoBinder], Bool)
</span><a href="#local-6989586621681114696"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Bndr"><span class="hs-identifier hs-type">Bndr</span></a></span><span> </span><span id="local-6989586621681114694"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114694"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCon.html#NamedTCB"><span class="hs-identifier hs-type">NamedTCB</span></a></span><span> </span><span id="local-6989586621681114692"><span class="annot"><span class="annottext">ArgFlag
</span><a href="#local-6989586621681114692"><span class="hs-identifier hs-var">vis</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681114691"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114691"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-1944"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVarBinder -&gt; TyCoBinder
</span><a href="GHC.Core.TyCo.Rep.html#Named"><span class="hs-identifier hs-var">Named</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; ArgFlag -&gt; TyVarBinder
forall var argf. var -&gt; argf -&gt; VarBndr var argf
</span><a href="GHC.Types.Var.html#Bndr"><span class="hs-identifier hs-var">Bndr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114694"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">ArgFlag
</span><a href="#local-6989586621681114692"><span class="hs-identifier hs-var">vis</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TyCoBinder -&gt; [TyCoBinder] -&gt; [TyCoBinder]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114691"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">)</span><span>
</span><span id="line-1945"></span><span>    </span><span class="annot"><a href="#local-6989586621681114696"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Bndr"><span class="hs-identifier hs-type">Bndr</span></a></span><span> </span><span id="local-6989586621681114690"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114690"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCon.html#AnonTCB"><span class="hs-identifier hs-type">AnonTCB</span></a></span><span> </span><span id="local-6989586621681114688"><span class="annot"><span class="annottext">AnonArgFlag
</span><a href="#local-6989586621681114688"><span class="hs-identifier hs-var">af</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>   </span><span class="hs-special">(</span><span id="local-6989586621681114687"><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114687"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681114686"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114686"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1946"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnonArgFlag -&gt; Scaled TcType -&gt; TyCoBinder
</span><a href="GHC.Core.TyCo.Rep.html#Anon"><span class="hs-identifier hs-var">Anon</span></a></span><span> </span><span class="annot"><span class="annottext">AnonArgFlag
</span><a href="#local-6989586621681114688"><span class="hs-identifier hs-var">af</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; Scaled TcType
forall a. a -&gt; Scaled a
</span><a href="GHC.Core.Type.html#unrestricted"><span class="hs-identifier hs-var">unrestricted</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Types.Var.html#tyVarKind"><span class="hs-identifier hs-var">tyVarKind</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681114690"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>   </span><span class="annot"><span class="annottext">TyCoBinder -&gt; [TyCoBinder] -&gt; [TyCoBinder]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TyCoBinder]
</span><a href="#local-6989586621681114687"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621681114686"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1947"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="#local-6989586621681114696"><span class="hs-pragma hs-type">go</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1948"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.Flatten.html#ty_con_binders_ty_binders%27"><span class="hs-pragma hs-type">ty_con_binders_ty_binders'</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-1949"></span></pre></body></html>